sql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crai8088
Forum Newbie
Posts: 5
Joined: Wed Jul 26, 2006 9:56 am

sql query

Post by crai8088 »

Can somebody help me please? I cannot find where i am going wrong! I have checked the manual and still cant see anything.

I am createing a form that will auto fill the fields once complete so that when a member returns to the form the fields they have already filled in are there. I have the rest of the form working its just getting the data from the db and into the correct fields. Here is the query i have so far.

Code: Select all

<?php
$MY_QUERY = "SELECT * FROM byb_players WHERE BYB_ID = '$BYB_ID'";
$SITEDATA = mysql_query($MY_QUERY);
$row = mysql_fetch_array($SITEDATA, MYSQL_ASSOC);

$STARS = $SITEDATA['STARS'];

echo "\nBYB_ID is", $BYB_ID 
 echo "\nSTARS is", $STARS 
 echo "\nSITEDATA is", $SITEDATA 
 echo "\nMY_QUERY is", $MY_QUERY 
 echo "\nrow is", $row
 ?>
and here is the html

Code: Select all

<input name='PokerStarsPlayerName' type=text value="<?php echo $STARS ?>">

Please point me in the right direction thanks
klarinetking
Forum Commoner
Posts: 59
Joined: Mon Jul 24, 2006 9:43 am

Post by klarinetking »

Hi,

The query looks correct, so try adding in some:

Code: Select all

mysql_query($MY_QUERY) or die ('Did not work' . mysql_error());
Also, try echoing out $MY_QUERY, to see if it's what you expect. Finally, make sure that your connection to the DB is working correctly.

klarinetking
crai8088
Forum Newbie
Posts: 5
Joined: Wed Jul 26, 2006 9:56 am

Post by crai8088 »

Hi thanks i added the error line,

And echoed the query

this is the return
BYB_ID iscrai8088 STARS is SITEDATA isResource id #21 MY_QUERY isSELECT * FROM byb_players WHERE BYB_ID = 'crai8088' row isArraySELECT * FROM byb_players WHERE BYB_ID = 'crai8088'
The second line is what i want BYB_ID is working fine its the SITEDATA is resource id #21 this should return a text value not a number value. Sorry i aint all that clued in on words and phrases i hope you understand.

Thanks
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

crai8088 wrote:Hi thanks i added the error line,

And echoed the query

this is the return
BYB_ID iscrai8088 STARS is SITEDATA isResource id #21 MY_QUERY isSELECT * FROM byb_players WHERE BYB_ID = 'crai8088' row isArraySELECT * FROM byb_players WHERE BYB_ID = 'crai8088'
The second line is what i want BYB_ID is working fine its the SITEDATA is resource id #21 this should return a text value not a number value. Sorry i aint all that clued in on words and phrases i hope you understand.

Thanks
$SITEDATA is your MySQL Result Resource return from the call to mysql_query(). You cannot 'echo' the value of a Result Resource, you must use mysql_result() or one of the mysql_fetch_* functions to fetch the data based on that result. Having said that, you do actually use mysql_fetch_array() in your script, with the result being assigned to the array $row; ergo, you need to access $row['STARS'].

Something else you should be aware of, it is much more practical and better practice to perform the SELECT statement on the column you want, not all records '*'. If all you require is the 'STARS' column, I'd change the query to

Code: Select all

SELECT STARS FROM byb_players WHERE BYB_ID = '{$BYB_ID}'
Post Reply