Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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
Php sql查询未插入到表中?_Php_Mysql_Sql - Fatal编程技术网

Php sql查询未插入到表中?

Php sql查询未插入到表中?,php,mysql,sql,Php,Mysql,Sql,我想您可能需要指定要查询的数据库 <?php $link = mysql_connect('localhost', 'sc2broad_testing', '1BananA2'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_query("INSERT INTO Persons (re) VALUES ('Peter')");

我想您可能需要指定要查询的数据库

<?php
$link = mysql_connect('localhost', 'sc2broad_testing', '1BananA2');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';


mysql_query("INSERT INTO Persons (re) VALUES ('Peter')");

mysql_close($link);

?>
如果没有,请尝试将
mysql\u查询
更改为:

mysql_select_db('db_name', $link)

然后,您可以检查查询是否正确,并测试它是否在php之外工作。

您发布的SQL语句没有“将值“peter”插入到persons行“re”中”。它向表中添加新行,并将“re”列值设置为“Peter”。这就是让你困惑的地方吗?还是去死(mysql\u error())。您假设查询已成功。您没有连接到任何数据库。在
mysql\u query()之前使用
mysql\u select\u db('db\u name',$link)
print("INSERT INTO Persons (re) VALUES ('Peter')");