我正在尝试通过制作一个html表单然后通过$ _GET方法添加接收数据来接收数据。每当我尝试提交数据时,我都会收到一条错误消息:“找不到您的文件”#39;在我的Chrome浏览器中,所以我尝试通过输入" localhost /....&#34来打开我的Chrome页面。在我的地址栏中,它显示了“未找到数据库”
这是我的PHP代码: -
<html>
<?php
$user_name = "root";
$password = "";
$database = "mysql"; //mysql is name of my database
$server = "localhost";
$db_handle = mysql_connect($server , $user_name, $password,"addresbook"); //adressbook is where all the tabels are
$db_found = mysql_select_db($database, $db_handle);
if (!$db_found) {
print "Database Found ";
$x=$_GET['fname'];
$y=$_GET['sname'];
$z=$_GET['address'];
$sql="INSERT INTO addresbook(First_Name,Surname,Address) VALUES('".$x."','".$y."','".$z."')";
mysql_query($sql,$db_handle);
}
else {
print "Database NOT Found ";
}
?>
</html>
这里是mt html代码: -
<form action="practic.php"method="get">
Firstname:<input type="text" name="fname"><br>
Lastname:<input type="text" name="sname"><br>
Address:<input type="text" name="address"><br>
<input type="submit">
</form>
顺便说一句,我正在使用wamp server.Thanks提前。
答案 0 :(得分:3)
$db_found
成功时会成立,所以你的条件应该是
if ($db_found) { // make DB changes etc.
并切换到MySQLi或PDO并使用已经提到的预准备语句,请参阅手册:
答案 1 :(得分:-1)
使用mysqli_connect
因为mysql_connect
现已弃用。
$db_handle = mysqli_connect($server , $user_name, $password,$database);
请参阅此处的连接
答案 2 :(得分:-1)
您可以更改代码以使用 if(video.readyState == 4){
$(window).scrollTop($(window).scrollTop()+1);
$(window).scrollTop($(window).scrollTop()-1);
}
或使用MysqLi
PDO
您的<?php
$user_name = "root";
$password = "";
$database = "mysql"; //mysql is name of my database
$server = "localhost";
$con = mysqli_connect($server,$user_name,$password,'adresbook');//adresbook is where all the tabels are
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
// Change database to "adresbook"
$db_found = mysqli_select_db($con,'adresbook');
if ($db_found) {
print "Database Found ";
$x=$_GET['fname'];
$y=$_GET['sname'];
$z=$_GET['address'];
$sql="INSERT INTO addresbook(First_Name,Surname,Address) VALUES('".$x."','".$y."','".$z."')";
mysqli_query($con, $sql);
}
else {
print "Database NOT Found ";
}
?>
应该与包含phpMyadmin
的数据库addresbook
一样。