du131642 2010-12-18 14:47
浏览 63
已采纳

一个文档中有多个mysql_query请求

I have a PHP document opening a connection to a database. Everything works fine - but as soon as I add one additional mysql_query request to the document, the mySQL server responds with a 500 internal server error.

Any idea why? Is there a reason that I cannot have multiple mysql_query requests in the one document?

thanks very much!

The offending PHP code is here (most of the echos are there for debugging reasons)

<?php
$q=$_GET["q"];

$con = mysql_connect('address.com', 'database', 'password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sql01_5789willgil", $con);

$sql1="SELECT * FROM place WHERE title = '".$q."'";
$result1 = mysql_query($sql1);
$row = mysql_fetch_array($result1);
$id=$row+1;


$sql2="SELECT * FROM place WHERE title = '".$q."'";

$result2 = mysql_query($sql2);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";

while($row = mysql_fetch_array($result2))
  {
  echo "<tr>";
  echo "<td>" . $row['title'] . "</td>";
  echo "<td>" . $row['description'] . "</td>";
  echo "<td>" . $row['latitude'] . "</td>";
  echo "<td>" . $row['longitude'] . "</td>";
  echo "<td>" . $row['image'] . "</td>";
  echo "</tr>";
  }
echo "</table>";


echo "ID equals " . $id;
echo "row equals " . $row;

mysql_close($con);
?>
  • 写回答

2条回答 默认 最新

  • doushang1890 2010-12-18 19:11
    关注
    $sql1="SELECT * FROM place WHERE title = '".
    mysql_real_escape_string($q, $con)."'"; <-- please escape
    
    $result1 = mysql_query($sql1, $con);    <-- always specify link identifier
    
    if ($result1)
    {
      $row = mysql_fetch_array($result1);  <-- always check result exist before fetch
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据