期望参数2为资源

期望参数2为资源

本文介绍了mysql_query()期望参数2为资源,字符串在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这行怎么了?

23. $result = mysql_query("INSERT INTO $tbl_name('city_id', 'city', 'state_id') VALUES('NULL, '.$city.","', '4421'') or die(mysql_error())");

每次我都会收到此错误消息:

I get this error message each time :

这是我的完整代码

<?php
// Get values from form
$city = explode(',', $_POST['city']);

//create a loop
if(isset($_POST['city'])) {


    $city = explode(',', $_POST['city']);
    $n = count($city);
    for($i=0; $i<$n; $i++) {
    $result = mysql_query("INSERT INTO $tbl_name(city_id, city, state_id) VALUES(NULL, '.$city.","', '4421')") or die(mysql_error());
    }
} if($result) {
    header('Location: index.html');
}


?>

推荐答案

这是因为语法不正确,您在INSERT查询中的列名不应用引号引起来:try

This is because of incorrect syntax and you column names in INSERT query should not be enclosed in quotes: try

$result = mysql_query("INSERT INTO ".$tbl_name."(city_id, city, state_id) VALUES(NULL, '".$city."','4421') or die(mysql_error()";

这篇关于mysql_query()期望参数2为资源,字符串在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:56