Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 26th, 2007, 4:51 PM   #1
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
SELECT statement

Hey guys I have been working on getting my selct statement to work for some time now and just can not get it to work I did manage to get it to stop returning errors but now it returns a blank page, so i went in to my DBMS and opend up the table double checked that i have every thing spelled the same as it is in there. I would be greatful if you could look at the code for me.

Quote:
<?
$host="localhost";
$username="----------";
$password="*******";
$db_name="kelvoron_testscripts";
$table_name="test1";

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$sql="SELECT name FROM $tabLE_name WHERE gender='male'";
$result=mysql_query($sql);

echo($result);


mysql_close();
?>
__________________
Good better best, never let it rest, untill your good is better and your better is the best.
Kelvoron is offline   Reply With Quote
Old Nov 26th, 2007, 6:38 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: SELECT statement

Kelvoron, how long have you been around, now? Not long enough to distinguish the differnce between code tags and quote tags? If you don't have two brain cells, try to rent one or two.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 26th, 2007, 6:39 PM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Re: SELECT statement

$tabLE_name and $table_name aren't the same thing. Make sure you have php error display enabled.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Nov 26th, 2007, 7:19 PM   #4
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
Re: SELECT statement

Oh my bad i changed it. it still does not work thoug thanks for cathing that for me Dameon. I checked my code against othr peoples and bought a MySQL book the code looks corect as far as i can see but i still get no return


i changed echo(results); to echo $results now it displays " Resource id #2 " X|
__________________
Good better best, never let it rest, untill your good is better and your better is the best.

Last edited by Kelvoron; Nov 26th, 2007 at 7:34 PM.
Kelvoron is offline   Reply With Quote
Old Nov 26th, 2007, 7:59 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: SELECT statement

Check your book regarding what "resource" means. As an example, a FILE * in C does not represent the contents of a file. It is merely an access mechanism.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 26th, 2007, 9:44 PM   #6
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Re: SELECT statement

Any basic example of the PHP MySQL functions will show you what to do with your $result variable. You certainly don't try to convert it to a string and display it. Reread your book and the online documentation before simply asking around for the next line -- both contain working examples that you can build from with a little personal effort.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Nov 27th, 2007, 2:28 PM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Re: SELECT statement

Look into the mysql_fetch_row() function, passing in your $result variable as the parameter.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Nov 29th, 2007, 1:01 AM   #8
Sanjay Aggarwal
Newbie
 
Join Date: Oct 2007
Posts: 12
Rep Power: 0 Sanjay Aggarwal is an unknown quantity at this point
Re: SELECT statement

The Variable names are case sensitive in PHP. See the variable you have used for table name.

Sanjay Aggarwal
Sanjay Aggarwal is offline   Reply With Quote
Old Nov 29th, 2007, 1:51 AM   #9
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 908
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: SELECT statement

Quote:
Originally Posted by Sanjay Aggarwal View Post
The Variable names are case sensitive in PHP. See the variable you have used for table name.

Sanjay Aggarwal
Thanks for repeating Dameon's post (second reply in this thread).
titaniumdecoy is offline   Reply With Quote
Old Nov 29th, 2007, 10:37 AM   #10
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 215
Rep Power: 3 pegasus001 is on a distinguished road
Re: SELECT statement

Quote:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
The $host variable is a string by itself, try removing the double quotes.

Just a thought, though.
__________________
You never test the depth of a river with both feet.
The believer is happy. The doubter is wise.
Free speech carries with it some freedom to listen.
The next generation will always surpass the previous one. It`s one of the never ending cycles of life.
pegasus001 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Select Statement Performance King Other Scripting Languages 6 Dec 1st, 2006 6:12 PM
Allow user to select a directory MegaArcon HTML / XHTML / CSS 11 Jun 5th, 2006 9:38 AM
reloading html select boxs...is there a better way? MegaArcon Python 13 May 26th, 2006 4:06 AM
sockets, problem with select() Wizard1988 C++ 0 Jan 15th, 2006 5:09 PM
Trouble with a swith statement cjaime C 10 Nov 8th, 2005 12:09 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC