My first PHP script
Posted: Mon Nov 30, 2009 5:38 am
Hi,
I've recently written some really basic php to retrieve a few rows from a database but it doesn't seem to to work. I've gone through the thread 'Debugging MySQL code .. a few tips.' and included all of those debugging tips but I still cant work out why no data is returned.
I'm sure its something really simple Ive over looked and wondered if someone can look at my code, below, and spot any mistakes I may have made?
This is my code: -
When I go to execute the above code this is the output on myy web page: -
I've recently written some really basic php to retrieve a few rows from a database but it doesn't seem to to work. I've gone through the thread 'Debugging MySQL code .. a few tips.' and included all of those debugging tips but I still cant work out why no data is returned.
I'm sure its something really simple Ive over looked and wondered if someone can look at my code, below, and spot any mistakes I may have made?
This is my code: -
Code: Select all
<?php
echo 'start<br>';
error_reporting(E_ALL);
if (($_SERVER['SERVER_NAME']!="www.blah,blah.com"))
{
die();
}
$username = "username";
$pwd = "password";
$host = "IP Address";
$dbname = "database name";
if (!($conn=mysql_connect($host, $username, $pwd)))
{
printf("error connecting to DB by user = $username and pwd=$pwd");
exit;
}
$db = mysql_select_db($dbname,$conn) or die("Unable to connect to database1");
$sql = "SELECT id, subgame_id, name, value FROM scores LIMIT 0 , 30";
$result = mysql_query($sql, $conn)or die("Unable to query local database <b>". mysql_error()."</b><br>$sql");
if ($result)
{
echo 'querying...<br>'.$sql.'<br>';
while($row = mssql_fetch_array($result))
{
echo 'sd';
echo "<li>" . $row["id"] . $row["subgame_id"] . $row["name"] . $row["value"] . "</li>";
}
echo 'queried<br>';
}
else
{
echo "database query failed.";
}
mysql_close();
?>
What am I doing wrong, I am sooooo stuck!start
querying...
SELECT id, subgame_id, name, value FROM scores LIMIT 0 , 30