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 equa开发者_JAVA百科ls " . $id;
echo "row equals " . $row;
mysql_close($con);
?>
$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
}
From this here:
$sql1="SELECT * FROM place WHERE title = '".$q."'";
$result1 = mysql_query($sql1);
$row = mysql_fetch_array($result1);
$id=$row+1;
You're adding '1' to an array. I tried this script my box:
<?php
$row = array("my", "name", "is", "foo");
$id = $row + 1;
?>
and received this error:
Fatal error: Unsupported operand types
Perhaps this is the issue the script is complaining about.
From this answer here: Apache Fall Back When PHP Fails it very well be why it's returning a 500
精彩评论