Jump to content

Connecting to a database


Icewolf

Recommended Posts

Hi 
Can anyone help me with this code? It looks like it is geting to the part where the SQL is ran but we are getting to the die part of the code. I am trying to figure out am I missing something. I am new to PHP so I am not sure if this is correct or not. I have searched the web and everything looks good to me but I can't figure out what I a missing.
Thanks
Andy

<?php $username = "Entered username";
$password = "entered password";
$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("pdogclan_points",$dbhandle)
  or die("Did this change");

//execute the SQL query and return records
$results = mysql_query("SELECT member_id, bank, reward_1, reward_2, reward_3, reward_4 FROM Points_Rewards") or die("Could Not Find Data");

//fetch tha data from the database
while ($row = mysql_fetch_array($result))   
echo "ID: {$row['member_id']}". "Bank: {$row['bank']}". "Reward 1: {$row['reward_1']}". "Reward 2: {$row['reward_2']}". "Reward 3: {$row['reward_3']}". "Reward 4: {$row['reward_4']}";//display the results

//close the connection
mysql_close($dbhandle);
?>

 

Link to comment
Share on other sites

$sql = 'SELECT ...';
$results = mysql_query($sql) or die(mysql_error() . '<BR>' . $sql);

Should show you if there is an error in the SQL statement.

 

On the other hand: you misspelled the variable name in the while loop

 

 

$results = mysql_query("SELECT member_id, bank, reward_1, reward_2, reward_3, reward_4 FROM Points_Rewards") or die("Could Not Find Data");

//fetch tha data from the database
while ($row = mysql_fetch_array($result))

 

$results is plural in the query, but singular in the fetch.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.