php 警告:mysql_query() 期望参数 1 是字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15175144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mysql_query() expects parameter 1 to be string
提问by Gaurav Gandhi
Error:Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\cdij\editquantity.php on line 8
错误:警告:mysql_query() 期望参数 1 为字符串,第 8 行 C:\wamp\www\cdij\editquantity.php 中给出的资源
Here is the Code:
这是代码:
<?php
$con=mysql_connect("localhost","root","","test");
$quantity=$_POST['txt_quantity'];
$name=$_POST['Fields'];
$table=$_POST['editwhat'];
$que="UPDATE `material` SET `material_quantity`='".$quantity."' WHERE `material_name`='".$name."'";
mysql_query($con,$que);
mysql_close($con);
?>
回答by niaccurshi
You need to swap the $con and $que paramters in your mysql_query function.
您需要在 mysql_query 函数中交换 $con 和 $que 参数。
回答by Mayukh Roy
You are using mysqli_querysyntax but using mysql_query! Well the best part of the mistake is, you need to upgrade to mysqli_queryand you are already half way around, which is really great.
您正在使用mysqli_query语法,但使用mysql_query!嗯,这个错误最好的部分是,你需要升级到mysqli_query并且你已经成功了一半,这真的很棒。
mysql_query is depricated. Check this link, and you are there. Cheers
mysql_query 已弃用。检查此链接,您就在那里。干杯
回答by Youn Elan
it probably means you are not connected to your database. check the credentials and add a test
这可能意味着您没有连接到您的数据库。检查凭据并添加测试
if($con)
{
$mysql_query($que);
}
else
{
echo "connection error";
}

