Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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 试图插入MYSQL表时参数无效?_Php_Mysql - Fatal编程技术网

Php 试图插入MYSQL表时参数无效?

Php 试图插入MYSQL表时参数无效?,php,mysql,Php,Mysql,产出为: 警告:mysql_query():提供的参数不是第18行/home/www/strusemissh.info/index.php中的有效mysql链接资源 编辑 我注意到您编辑了代码() 更改此项: if (! $con) { echo 'Could not CONNECT'; } echo 'Connected to Database'; $sql="INSERT INTO Persons VALUES 'Struan' , 'Smith',

产出为:

警告:mysql_query():提供的参数不是第18行/home/www/strusemissh.info/index.php中的有效mysql链接资源

编辑 我注意到您编辑了代码()

更改此项:

if (! $con)
    {
    echo 'Could not CONNECT';
    }
    echo 'Connected to Database';
    $sql="INSERT INTO Persons VALUES 'Struan' , 'Smith', 13)";
    mysql_query($con, $sql);
    mysql_close($con);
    ?>
致:

使用
mysql.*
函数时,
$con
在末尾。加上一个缺少括号的值()


原始答案 您的代码存在一些问题

以下字段末尾缺少分号:

$sql="INSERT INTO `Persons` VALUES ('Struan' , 'Smith', 13)";
mysql_query($sql,$con);
mysql_close($con);
(并删除了值前面的
),并且对
值使用双引号而不是单引号

替换为:

mysql_query($con,"INSERT INTO Persons ( VALUES ("Struan" , "Smith", 13)")
当使用不推荐使用的
mysql.*
函数时,Plus
$con
会在末尾出现

在准备好的语句或PDO中使用
mysqli.*

请参考MySQL手册中的插入函数:
-

如果您仍然热衷于使用(已弃用的)
mysql*
函数,请访问Tizag.com,这是一个非常好的教程网站

<强>请考虑使用 > <代码> MySqLI**<代码>函数,使用或.< /P> 还有明显的语法高亮提示…颜色看起来不对,是吗

您可以将
\“
与双引号字符串一起使用。但对于mySQL查询,您更喜欢使用单引号值

注意:下一个编译错误是缺少分号。然后是运行时问题,因为参数顺序不正确:

 "                                      "
 string starts here .... string ends here

使用query as
INSERT-INTO-Persons-VALUES('Struan','Smith',13)
非常感谢您的回答,但是现在由于错误#2005,我无法登录到MYSQL服务器。对此有什么想法吗?您忘记了单引号而不是双引号(对于值)修复,再次感谢@JustinIurman
mysql_query("INSERT INTO `Persons` VALUES ('Struan', 'Smith', 13)", $con);
 "                                      "
 string starts here .... string ends here
resource mysql_query ( string $query [, resource $link_identifier = NULL ] )