警告:mysqli_select_db()恰好需要2个参数,其中1个给定 [英] Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in

查看:59
本文介绍了警告:mysqli_select_db()恰好需要2个参数,其中1个给定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者,也是一个文凭学生...我已经使用本地主机创建了数据库...我在查看我的数据库时遇到问题...请帮助我...我希望你能以完整的代码为我提供帮助.. .这是错误...

im a beginner and also a diploma student... i have created database using localhost... im having problem viewing my database... please help me... i hope u can help me with a full code... this is the ERROR...

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">&nbsp;</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

If you check the php manual here: http://php.net/manual/fr/mysqli.select-db.php

您将看到函数mysqli_select_db在输入中包含两个参数.

You will see the function mysqli_select_db take two params in input.

bool mysqli_select_db(mysqli $ link,字符串$ dbname)

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_select_db()恰好需要2个参数,其中1个给定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆