我的PHP代码中出现此错误:
警告:mysql_select_db()期望参数1为字符串,资源 在第144行的C:\ xampp \ htdocs \ WEBDEV \ save.php中给出表单提交 失败!
这是我的代码:
<?php
$connect = mysql_connect ("localhost", "root");
$db = mysql_select_db ($connect, "signup");
$idnum = $_POST ['idnum'];
$fname = $_POST ['fname'];
$lname = $_POST ['lname'];
$course = $_POST ['course'];
$yrlvl = $_POST ['yrlvl'];
$pass = $_POST ['pass'];
$Query = mysql_query ("insert into admin (idnum, fname, lname, course, yrlvl, pass)
values ('$idnum', '$fname', '$lname', '$course', '$yrlvl', '$pass')", $connect);
if ($Query)
{
print "Form submitted successfully! <br>";`e`enter code here`nter code here`
}
else
{
print "Form submitted failed! <br>";
}
?>
答案 0 :(得分:0)
哟需要在数据库链接标识符前面使用“ your_db_name ”。
假设"signup"
是您的数据库名称:
$db = mysql_select_db ("signup", $connect);
警告:
不推荐使用mysql_connect()
和mysql_select_db()
并从php 7.0中删除。请改用mysqli_connect()
。例如:
$connection = mysqli_connect('localhost', 'username', 'password', 'database');
类似地,mysql_select_db()可以实现为:
mysqli_select_db($link, "signup");