| | |
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: 89
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, you don't have to do anything to get it
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 |
Tag cloud for PHP
.htaccess action ajax apache api array auto beginner binary broken cakephp checkbox class cms code cron curl database date dehasher destroy directory display domain download dynamic echo email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image include insert integration ip java javascript joomla limit link load login loop mail masterthesis menu mlm mod_rewrite multiple mysql oop paypal pdf php popup problem query radio random record recursion regex remote script search security server sessions sms soap source space sql syntax system table tutorial update upload url validation validator variable video web xml youtube






