ACK yet another newb question. This time about SQL
I tried to make connection to a database on a free provider, just to see if I could do it. All I had the script do was have it show the only table there is in the database I made.
When I ran the script, it said: SERVER ERROR! Error message:
Premature end of script headers: testsql.php
testsql.php
<?php
$user = "**";
$pass = "";
$host = "";
$dbdb = "****";
if (!mysql_select_db($dbdb, mysql_connect($host, $user, $pass)))
{
echo "Cannot connect to Database.";
exit();
}
unset($user);
unset($pass);
unset($host);
unset($dbdb);
$sql = "SELECT pres_name FROM PRESIDENT";
$res = mysql_query($sql);
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
echo "$row";
}
}
else
{
echo "Nothing to show in database";
}
?>
I replaced the server info with ***** hehe.
The content of the table is really simple, I used it in some SQL lesson book:
PRESIDENT
pres_name | birth_yr | yrs_serv | death_age | party | state_born
Adams J | 1735 | 4 | 90 | Federalist | Massachusetts
Madison J | 1751 | 8 | 85 | Demo-Rep | Virginia
So all I asked the script to do was show the 2 names in this table. But as I said, I seemed to have done something wrong with the connecting part. I'm pretty sure I got the username, host and password right.... looks confused
Any help is greatly appreciated 🙂