Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   SELECT statement (http://www.programmingforums.org/showthread.php?t=14594)

Kelvoron Nov 26th, 2007 4:51 PM

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();
?>


DaWei Nov 26th, 2007 6:38 PM

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.

Dameon Nov 26th, 2007 6:39 PM

Re: SELECT statement
 
$tabLE_name and $table_name aren't the same thing. Make sure you have php error display enabled.

Kelvoron Nov 26th, 2007 7:19 PM

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|

DaWei Nov 26th, 2007 7:59 PM

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.

Dameon Nov 26th, 2007 9:44 PM

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.

Infinite Recursion Nov 27th, 2007 2:28 PM

Re: SELECT statement
 
Look into the mysql_fetch_row() function, passing in your $result variable as the parameter.

Sanjay Aggarwal Nov 29th, 2007 1:01 AM

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

Sanjay Aggarwal

titaniumdecoy Nov 29th, 2007 1:51 AM

Re: SELECT statement
 
Quote:

Originally Posted by Sanjay Aggarwal (Post 137791)
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).

pegasus001 Nov 29th, 2007 10:37 AM

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.


All times are GMT -5. The time now is 3:28 AM.

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