Heads Up! Just starting out in PHP so I apologize in advance if this is some sort of n00b error. I have a little script in PHP which reads a table from a MySQL database and provides the values of a single column as a drop-down list. The PHP code is as follows:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
$dbc = mysql_connect("localhost", "someDBuser", "somecorrectpass");
$db = mysql_select_db("someDB");
$results= mysql_query("SELECT name FROM sometable");
?>
<select name="eventid">
<option value="0">Choose</OPTION>
<?php
while($row = mysql_fetch_array($results)) {
echo '<option value="'.$row['name'].'">'. $row['name'].'</option>';
}
?>
</select>
</form>
</body>
</html>
Now when I call the file from the browser, I get a Blank Screen. I enabled PHP Error reporting and get the following error Fatal error: Call to undefined function mysql_connect() in /var/www/html/testdel.php on line 12
.
Next I tried running the file in the backend using the PHP command. It ran fine and gave me the required html output like so:
$ php /var/www/html/testdel.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form method="post" action="/var/www/html/testdel.php">
<select name="eventid">
<option value="0">Choose</OPTION>
<option value="Ex1005">Ex1005</option><option value="Ex1009">Ex1009</option><option value="user1">user1</option></select>
</form>
</body>
</html>
And when I put this output in a file (say "testdel.html", for example), I get the correct output.
What am I doing wrong in the original PHP file? Is it something related to permissions? The current file permissions are 644. Or do I need to include(use) some module?