简体   繁体   English

我无法将数据插入数据库

[英]I can't insert data into my database

I don't know why, but my data doesn't go into my database 'users' with the table 'data'. 我不知道为什么,但是我的数据没有与表“ data”一起进入数据库“ users”。

<html>
<body>
<?php

date_default_timezone_set("America/Los_Angeles");

include("mainmenu.php");

$con = mysql_connect("localhost", "root", "g00dfor@boy");
 if(!$con){
  die(mysql_error());
}

$usrname = $_POST['usrname'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$password = $_POST['password'];
$email = $_POST['email'];

mysql_select_db(`users`, $con) or die(mysql_error());

mysql_query(INSERT INTO `users`.`data` (`id`, `usrname`, `fname`, `lname`, `email`, `password`) VALUES (NULL, '$usrname', '$fname', '$lname', '$email', 'password')) or die(mysql_error());

mysql_close($con)

echo("Thank you for registering!");

?>    
</body>
</html>

All i get is a blank page. 我所得到的只是空白页。

It looks like you need to enclose the query you give to mysql_query() in double quotes 1 : 看来您需要将对mysql_query()的查询括在双引号1中

mysql_query("INSERT INTO ... ");

You also need to terminate your call to mysql_close() with a semicolon, as others pointed out. 正如其他人指出的那样,您还需要使用分号终止对mysql_close()调用。


1 The same applies for mysql_select_db() , as @marcog pointed out in the comment below. 1同样适用于mysql_select_db() ,如@marcog在下面的注释中指出。

because of this line 因为这条线

mysql_close($con)

you forgot semicolon 你忘了分号

mysql_close($con);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法在数据库Symfony 2.4和准则中插入数据 - I can't insert data in my database symfony 2.4 and doctrine 我无法将数据插入数据库phpmyadmin - I can't insert my data to database phpmyadmin 我无法将数据插入我的数据库,它与数据库有连接,但我无法添加记录 - I can't Insert The data to my database,it has connection runing with database but i can't add the records 无法将我的数据插入数据库 phpmyadmin - can't insert my data to database phpmyadmin 试图将数据库中的数据检索到我的复选框中,问题是我无法将复选框插入数据库 - Tried to retrieve data in the database into my checkboxes, the problem is I can't insert the checked box into the database 为什么我不能使用Webhost在数据库中插入数据? - Why I can't insert data on my database using my webhost? 我无法在数据库中插入数据。 我要去哪里错了? - I can't insert data in my database. Where I'm going wrong? 我无法将数据插入数据库。 始终使用代码的else部分 - I can't insert data into my database. Always uses the else part of the code 我找不到用于代码的正则表达式和将数据插入数据库的代码 - I can't find regex for my coding and code to insert that data to database 无法从 laravel 在我的数据库中插入数据 - Can't insert data on my database from laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM