Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL不会插入文本,只插入数字_Mysql_Database_Insert - Fatal编程技术网

MySQL不会插入文本,只插入数字

MySQL不会插入文本,只插入数字,mysql,database,insert,Mysql,Database,Insert,我试图将$\u POST中的值插入MySQL表中,如果我在表单中输入数字,效果会很好。然而,每当我键入文本时,就会收到一条消息,如“字段列表”中的未知列“exampleinput”。我是一个相当业余的程序员,所以我可能缺少一些基本的东西。Mysql字段已设置为VARCHAR。我的代码如下所示: mysql_query("INSERT INTO users2 (username, primaryemail, password) VALUES($username, $newE

我试图将$\u POST中的值插入MySQL表中,如果我在表单中输入数字,效果会很好。然而,每当我键入文本时,就会收到一条消息,如“字段列表”中的未知列“exampleinput”。我是一个相当业余的程序员,所以我可能缺少一些基本的东西。Mysql字段已设置为VARCHAR。我的代码如下所示:

mysql_query("INSERT INTO users2
            (username, primaryemail, password) VALUES($username, $newEmail, $newPassword)")
            or die(mysql_error());

如果要在表中插入文本,需要在输入周围添加引号:

mysql_query("INSERT INTO users2 (username, primaryemail, password)
            VALUES('$username', '$newEmail', '$newPassword')");

你也应该考虑使用你的数据库来执行你的查询,因为MySqL**函数现在被弃用。

如果你想在表格中插入文本,你需要在你的输入中添加引号:

mysql_query("INSERT INTO users2 (username, primaryemail, password)
            VALUES('$username', '$newEmail', '$newPassword')");

你也应该考虑使用你的数据库来执行你的查询,因为MySqL**函数现在被弃用。

你也可以使用PDO,你也可以使用PDO。