Icewolf Posted March 25, 2013 Share Posted March 25, 2013 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/276111-connecting-to-a-database/ Share on other sites More sharing options...
DavidAM Posted March 25, 2013 Share Posted March 25, 2013 $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. Quote Link to comment https://forums.phpfreaks.com/topic/276111-connecting-to-a-database/#findComment-1420856 Share on other sites More sharing options...
Icewolf Posted March 26, 2013 Author Share Posted March 26, 2013 Thank you we got it to work. Quote Link to comment https://forums.phpfreaks.com/topic/276111-connecting-to-a-database/#findComment-1421071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.