Ok can anyone tell me if the code below has a problem. All i am trying to do is make this connect to a database without username or password and just display the info in the database of some names and towns, the database name is data and the table name the data is in is called personal, thats it. The error i am getting is "Could not change into the database" displayed in the browser.
Thank you for any advice.
<HTML>
<BODY>
<?php
personal.php
$connection=mysql_connect("localhost","","");
if (!$connection) {
echo "Could not connect to MySQL server!";
exit;
}
$db=mysql_select_db("data",$connection);
if (!$db) {
echo "Could not change into the database";
exit;
}
$sql="SELECT * FROM personal";
$mysql_result=mysql_query($sql,$connection);
$num_rows=mysql_num_rows($mysql_result);
if ( $num_rows == 0 ) {
echo "Sorry there is no information";
} else {
we have results
while ($row=mysql_fetch_array($mysql_result))
{
$name=$row["name"];
$town=$row["town"];
display results
echo "$name : $town<BR>";
}
} # end else
mysql_close($connection);
?>
</BODY>
</HTML>