连接DB的mySql错误

时间:2014-10-10 08:58:28

标签: mysql database

我在尝试插入数据库时​​不断收到此错误。 " mysqli_select_db()预计正好有2个参数,1在"

中给出
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="#test"; // Database name 
$tbl_name="appoint"; // Table name 

// Connect to server and select databse.
$con = mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
if(! $con )
{
  die('Could not connect: ' . mysql_error());
}

$customer=$_POST['Name']; 
$assist=$_POST['Assisstant'];
$service=$_POST['Service']; 
$date=$_POST['date']; 
$time=$_POST['time']; 

$sql="INSERT INTO $tbl_name (cus_name, emp_name, date, time, service) 
VALUES ('$customer', '$assist', '$date', '$time', '$service');";

mysqli_select_db("$db_name")or die("cannot select DB");
$retval = mysql_query( $sql, $con );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($con);

1 个答案:

答案 0 :(得分:3)

你在程序上使用它。

来自the docs;

bool mysqli_select_db ( mysqli $link , string $dbname )

因此;

mysqli_select_db($con, $db_name)or die("cannot select DB");