I am having an interesting problem with php and mysql.
I am trying to write a simple connect and query script to mysql on my localhost(same host as webserver) and am having some problems retrieving data, also anything that is below the php code disappears when you do a view source on the web site.
I am running apache2, I have installed php5 and other php commands work like echo.
Here is the php code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$con = mysql_connect("localhost", "user", "pass"); // corrected mysql spellings
if(!$con)
{
die('could not connect to server: ' . mysql_error());
}
mysql_select_db("db", $con);
$result = mysql_query("SELECT * FROM user_list");
while($row = mysql_fetch_array($result))
{
echo $row['name'] . "<br />";
}
mysql_close($con);
echo "hello";
?>
trying testing
</body>
</html>
Please let me know if there is anything I should check to see if my server setup is correct.
Thanks,
Andy
You have written mysl_connect
instead of mysql_connect
on line 8.
If you had error reporting turned on (which you should do only for development), you would have seen an error message telling you about this.
can you try this way ?
mysql_connect($host, $user, $password) or die ("Error connection");
mysql_select_db($nameBDD) or die ("Error BDD");
while ($row = mysql_fetch_assoc(mysql_query($query)))
...
First of all, are you sure that your error_reporting is at E_ALL | E_STRICT in your php.ini ? Secondly, add a or die(mysql_error())
after the mysql_select_db