Hello. Im completely new to PHP, but have been doing my research and picking things up quite quickly. However I have a problem which im sure is really stupid. I created a test script to ensure that all the aspects of my setup are working correctly. I know that PHP, phpmyadmin, mysql and apache are all running fine, but im still getting a glitch.
Below is the script I am testing with. It gets as far as querying the table, but then all i get is the 'couldnt query "$table"' line when i test it. Could anybody see what i may have done wrong? The password variable is usually filled in.
<html>
<head>
<title>database test page</title>
</head>
<body>
<?php
$server="localhost";
$user="root";
$pass="********";
$database="test";
$table="members";
#connect to mysql
$connection = mysql_connect( $server, $user, $pass ) or die( "sorry, cannot connect to MySQL");
echo( "Congratulations $user! you connected to MySQL!<br>");
#tell it which db to use
$rs = mysql_select_db($database, $connection) or die ("couldn't find the db");
echo( "loaded db<br>");
#make sql query
#sql = "select * from $table";
#do it
$rs = mysql_query( $sql, $connection) or die ("couldn't query '$table'");
echo( "loaded db data<br>");
#make user display table
$list = "<table border=\"1\">";
$list .= "<tr><th>user id</th>";
$list .= "<th>username</th>";
$list .= "<th>pw</th></tr>";
#create loop for each record in db table
while ($row = mysql_fetch_array($rs))
{
$list .= "<tr>";
$list .= "<td>".$row["user_id"]."</td>";
$list .= "<td>".$row["username"]."</td>";
$list .= "<td>".$row["password"]."</td>";
$list .= "</tr>";
}
$list .= "</table>";
#show table
echo($list)
?>
</body>
</html>
Thanks, Lee