я новичок, а также студент-диплом … я создал базу данных, используя localhost … im, имея проблемы с просмотром моей базы данных … пожалуйста, помогите мне … я надеюсь, что вы сможете помочь мне с полным кодом … это Ошибка…
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\SLR\View S110 PC01.php on line 10 cannot select DB
это мой код …
<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="slr"; // Database name $tbl_name="s110_pc01"; // Table name // Connect to server and select databse. mysqli_connect("$host", "$username", "$password")or die("cannot connect"); mysqli_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysqli_query($sql); $count=mysqli_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Software ID</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Software Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Installed Date</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Expiry Date</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Product Key</strong></td> </tr> <?php while($rows=mysqli_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['soft_id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['soft_name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['installed_date']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['expiry_date']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['product_key']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE soft_id='$soft_id'"; $result = mysqli_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=View S110 PC01.php\">"; } } mysqli_close(); ?> </table> </form> </td> </tr> </table>
в<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="slr"; // Database name $tbl_name="s110_pc01"; // Table name // Connect to server and select databse. mysqli_connect("$host", "$username", "$password")or die("cannot connect"); mysqli_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysqli_query($sql); $count=mysqli_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Software ID</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Software Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Installed Date</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Expiry Date</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Product Key</strong></td> </tr> <?php while($rows=mysqli_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['soft_id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['soft_name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['installed_date']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['expiry_date']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['product_key']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE soft_id='$soft_id'"; $result = mysqli_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=View S110 PC01.php\">"; } } mysqli_close(); ?> </table> </form> </td> </tr> </table>
Если вы проверите руководство по php здесь: http://php.net/manual/fr/mysqli.select-db.php
Вы увидите, что функция mysqli_select_db
принимает два параметра ввода.
bool mysqli_select_db (mysqli $ link, string $ dbname)
Таким образом, вы должны иметь
// Connect to server and select databse. $conn = mysqli_connect($host, $username, $password) or die("cannot connect"); mysqli_select_db($conn, $db_name) or die("cannot select DB");
Вам не нужна отдельная функция для выбора базы данных в функции mysqli,
Этот метод более чем достаточно для подключения и выбора базы данных,
// Connect to server and select databse. $conn = mysqli_connect($host, $username, $password,$db_name)or die("cannot connect");
In Mysqli you have to pass two parameters. 1) sql Connection 2) sql query example : <?php // Connect to server and select database. $con=mysqli_connect("$host", "$username", "$password","$db_name")or die("cannot connect server "); $name="abc"; $email="abc@gmail.com"; $sql="INSERT INTO $tbl_name(name, email)VALUES('$name','$email')"; $result=mysqli_query($con,$sql); mysqli_close($con); ?>