I use the code above, the start of the script is fine. But after adding your code and some other example code, I still can't see the user name or password output to the screen. Anyone know what I could be doing wrong? My code now looks exactly like this.
Code: Select all
<?php
$username = "kel";
$password = "meme222";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("test",$dbhandle)
or die("Could not select test");
echo "Selected Test<br>";
//execute the SQL query and return records
$result = mysql_query("SELECT name, pswd");
///what do i put here to bring my query to screen
while($row = mysql_fetch_array($result)) {
$name = $row['name'];
$pwd = $row['pswd'];
}
echo $name;
echo $pwd;
//close the connection
mysql_close($dbhandle);
?>
I'm sorry I'm asking so many questions but I'm really new at this. Also turned out the book we had is outdated. The only conclusion I can come to is I'm returning NULL, in which it wouldn't display to screen. Very confused on why this would be because my databases name is test, tables name is user, table rows are name, pswd. But I'm getting nothing back on the return.