简体   繁体   中英

Server Error - HTTP 500 (INTERNAL SERVER ERROR) Only when visiting this one PHP page

I am a beginner at PHP, I have made a few pages which insert into my MySQL DB, as well as retrieve. This one page always gives me the 500 error, but my other PHP pages dont (Such as the INSERT record). Running PHP 5.2, apache 2.2

<?php
$con = mysql_connect("localhost", "XXXX", "XXXX");
if (!$con) 
{
 die('Could not connect: ' . mysql_error());
 }
  mysql_select_db("equipment", $con);

$result = mysql_query("SELECT * FROM equipmentwanted");

while $row = mysql_fetch_array($result))
    {
echo $row['fname'] . " " . $row['lname'];
echo "<br />";
    }

mysql_close($con);

?>

Some things to look at:

1) Not checking for query failures:

$result = mysql_query("SELECT * FROM equipmentwanted") or die(mysql_error());
                                                      ^^^^^^^^^^^^^^^^^^^^^^
  mysql_select_db("equipment", $con) or die(mysql_error());
                                    ^^^^^^^^^^^^^^^^^^^^^^

2) Syntax error:

while $row = mysql_fetch_array($result))
      ^--- missing a (

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM