我有一个小代码片段,但它现在不是真的工作。我总是有资源id 5错误。我在google上搜索了一些指针,但没有找到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

最佳答案

您正在使用两次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);
}

关于php - mysql错误资源id#5,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12686304/

10-09 00:50