我有这个小代码片段,但它现在还没有真正起作用。我总是有资源ID#5错误。我在谷歌搜索了几个指针,但没有发现mutch通过这个问题。这是我的代码
<?php
include 'load_db.php';
$var1 = $_POST["gender_1"];
$var2 = $_POST["gender_2"];
$var3 = $_POST["age"];
$sql = mysql_query("SELECT url FROM links WHERE gender ='".$var1."' AND gender1 ='".$var2."' AND age ='".$var3."'");
$result_1 = mysql_query($sql)
OR die("Error: $sql </br>".mysql_error());
echo $result_1;
?>
错误:资源ID#5
答案 0 :(得分:4)
您正在使用mysql_query()
两次,从mysql_query()
删除$sql
:
$var1 = mysql_real_escape_string($_POST["gender_1"]);
$var2 = mysql_real_escape_string($_POST["gender_2"]);
$var3 = mysql_real_escape_string($_POST["age"]);
$sql = "SELECT url FROM links WHERE gender ='".$var1."' AND gender1 ='".$var2."' AND age ='".$var3."'";
$result_1 = mysql_query($sql) OR die("Error: $sql </br>".mysql_error());
然后循环结果:
while($row = mysql_fetch_array($result_1)){
print_r($row);
}
答案 1 :(得分:0)
一些指示:
$sql = mysql_query("SELECT url FROM links WHERE gender ='".$var1."' AND gender1 ='".$var2."' AND age ='".$var3."'"); $result_1 = mysql_query($sql) OR die("Error: $sql </br>".mysql_error());
你两次调用sql_query ..
将$ sql更改为
$sql = "SELECT url FROM links WHERE gender ='".$var1."' AND gender1 ='".$var2."' AND age ='".$var3."'";