Jump to content

Archived

This topic is now archived and is closed to further replies.

cryp7

A Little Help...Displaying

Recommended Posts

Ive Done A Search and cant find ne thing that helps me

i got...

[code]
<?php
mysql_connect("localhost", "xxx", "xxx") or
die("Could not connect: " . mysql_error());
mysql_select_db("xxx");


$img_skin = "SELECT img_skin FROM character WHERE username='admin'";
$img_skin_res = mysql_query($img_skin);

$name = "SELECT name FROM character WHERE username='admin'";
$name_res = mysql_query($name);

$row_img=mysql_fetch_array($img_skin_res);
$img_skin_string = $row_img['img_skin'];

$row_name=mysql_fetch_array($name_res);
$name_string = $row_name['name'];

echo "IMG: $img_skin_string, Name: $name_string";

mysql_free_result($img_skin_string);
mysql_free_result($name_string);
?>
[/code]

What i want is the results "img_skin" and "name" for admin, which are stored in the "character" table, to be printed...ive tried searching and doing everything that i can think of now im stuck :S

And This is what i get

[code]
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/andy/public_html/character.php on line 103

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/andy/public_html/character.php on line 106
IMG: , Name:
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/andy/public_html/character.php on line 111

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/andy/public_html/character.php on line 112
[/code]

so help would be loved - thxs

Share this post


Link to post
Share on other sites
Try this:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
mysql_connect("localhost", "xxx", "xxx") or
die("Could not connect: " . mysql_error());
mysql_select_db("xxx");


$img_skin = "SELECT img_skin,name FROM character WHERE username='admin'";
$img_skin_res = mysql_query($img_skin) OR die(mysql_error());

$row_img=mysql_fetch_array($img_skin_res);
$img_skin_string= $row_img['img_skin'];
$name_string = $row_img['name'];

echo "IMG: $img_skin_string, Name: $name_string";

mysql_free_result($img_skin_res);

?>[/quote]

If it still doesn't work then you will get an error for the SQL statement which will tell you where in the wuery the error is.

Regards
Liam

Share this post


Link to post
Share on other sites
thxs for the reply - your right it didn't work but i told me something new...

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'character WHERE username='admin'' at line 1
[/quote]

this doesn't actually mean anything to me :S soz

thxs again

Share this post


Link to post
Share on other sites
The word "character" is probably a reserved word in MySQL, surround it with back ticks (`):
[code]<?php
$img_skin = "SELECT img_skin,name FROM `character` WHERE username='admin'";
$img_skin_res = mysql_query($img_skin) OR die('Problem with query:' . $img_skin . '<br>' . mysql_error());
?>[/code]
I always print out the query that caused the problem in the "or die" clause.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.