| | |
What am I doing wrong?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 85
Reputation:
Solved Threads: 2
I'm learning PHP & MySQL. While trying to folllow a tutorial I am not getting the erxpected result which is simply to retrieve a little data out of a table with a query.
Here is my PHP code:
and i have attached a screenshot of my very simple table. Thanks for the time and help.
Here is my PHP code:
php Syntax (Toggle Plain Text)
<?php //1. Create a database connection $connection = mysql_connect("localhost", "kingdomc_mtech", "busine$$"); if (!$connection) { die("Database connection failed: " . mysql_error()); } //2. Select a database to use $db_select = mysql_select_db("kingdomc_learning", $connection); if (!$db_select) { die ("Database selection failed: " . mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SQL lesson1</title> </head> <body> <?php //3. Perform database query $result = mysql_query("SELECT * FROM subjects", $connection); if(!$result) { die ("Database query failed: " . mysql_error()); } //4. Use returned data while ($row = mysql_fetch_array($result)); { echo $row[0]." ".$row[2]."<br/>"; } ?> </body> </html> <?php //5. Close connection mysql_close($connection); ?>
and i have attached a screenshot of my very simple table. Thanks for the time and help.
Last edited by Ezzaral; Sep 9th, 2009 at 4:59 pm. Reason: Changed code tags for clarity.
php Syntax (Toggle Plain Text)
<?php //1. Create a database connection $connection = mysql_connect("localhost", "kingdomc_mtech", "busine$$"); if (!$connection) { die("Database connection failed: " . mysql_error()); } //2. Select a database to use $db_select = mysql_select_db("kingdomc_learning", $connection); if (!$db_select) { die ("Database selection failed: " . mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SQL lesson1</title> </head> <body> <?php //3. Perform database query $result = mysql_query("SELECT * FROM subjects", $connection); if(!$result) { die ("Database query failed: " . mysql_error()); } //4. Use returned data while ($row = mysql_fetch_array($result)); { echo $row[0]." ".$row[2]."<br/>"; } ?> </body> </html> <?php //5. Close connection mysql_close($connection); ?>
sql Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM subjects" );
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
![]() |
Similar Threads
- My CD-RW plays but won't burn. What could be wrong?? Help Please? (Storage)
- Retrieve email I sent to the wrong person (Web Browsers)
- Ram voltage wrong?? (Motherboards, CPUs and RAM)
- Am I going about this the wrong way (IT Professionals' Lounge)
- wats wrong with imesh??? (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: mobile redirect
- Next Thread: Simple text Verification
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion remote script search seo server sessions sms soap source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






