Jump to content


Php - MySQL 'result with id'


9 replies to this topic

#1 Ripix

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 13 September 2005 - 12:12 PM

what am I doing wrong???? :(
I just can't figure it out ! I learnt this from another tutorial , maybe it's the tut.
I realy dunno ! :D


this is the code:
<?php 
$db = mysql_connect("localhost", "root", ""); 
mysql_select_db("art",$db); 
$result = mysql_query("SELECT * FROM table WHERE id=$id",$db); 
$myrow = mysql_fetch_array($result); 
echo "Name: ".$myrow["name"]; 
echo "<br>creator: ".$myrow["creator"]; 
echo "<br>resolution: ".$myrow["resolution"]; 
echo "<br>Size: ".$myrow["size"]; 
echo "<br>date: ".$myrow["date"]; 
?>

And I'm still gettin this :

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\vhosts\phase02.org\httpdocs\test.php on line 12

where's the problem, can please someone help me !

Edited by Ripix, 13 September 2005 - 12:14 PM.


#2 Ripix

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 13 September 2005 - 03:16 PM

ty m8 !


but it still doesn't work ... :P

so now I have this :

<?php 

$result = mysql_query("SELECT * FROM table WHERE id= '$id' ") 
or die(mysql_error()); 
while ($myrow = mysql_fetch_array($result) )
echo "Name: ".$myrow["name"]; 
echo "<br>creator: ".$myrow["creator"]; 
echo "<br>resolution: ".$myrow["resolution"]; 
echo "<br>Size: ".$myrow["size"]; 
echo "<br>date: ".$myrow["date"]; 
?>

with the config file include of cours, actually realy stupid to forgot that !
anyway, now I get this error and also can't find out how to solve it.

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 'table WHERE id= ''' at line 1

can someone help me ... ?
plz :D

ty anyway !

already ty Ben Bale :(

#3 Antonio

    Young Padawan

  • Members
  • Pip
  • 4 posts
  • Interests:Computers and Skateboarding

Posted 13 September 2005 - 05:05 PM

Looks like $id is not defined, try using $id = $_GET['id'] or $_POST['id']

#4 liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 13 September 2005 - 06:20 PM

$result = mysql_query("SELECT * FROM table WHERE id= '$id' ")

is table the name of you mysql table? if not go like this

$result = mysql_query("SELECT * FROM `table` WHERE id= '$id' ")


change table to the name of the table...

#5 Antonio

    Young Padawan

  • Members
  • Pip
  • 4 posts
  • Interests:Computers and Skateboarding

Posted 13 September 2005 - 06:22 PM

That's not the error he is recieving, he masked his table so you wouldn't know what it is, the error states that he has an error near id='' meaning that id is null, so my post would assure it isn't null

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 September 2005 - 08:29 PM

Actually, your post would just change the variable, that's all. He could have an actual $id variable some where... But from the looks of his code, then yes, using the globals would help (if he picks the right one).

$result = mysql_query("SELECT * FROM table WHERE id = '".$_GET['id']."'") 
or die(mysql_error());
And i swear i've had the same error, and the problem was just spacing. Change your code to what i have above (only change the $_GET['id'] var if neccessary), and try again.

#7 Ripix

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 14 September 2005 - 08:23 AM

hmm guys it didn't work, still the same error again !

but you know ! Maybe it's because of this :

I called that file test.php now , but when I put the link test.php?id=1
I want the data of the row where the id is 1 to come up .

sorry my english isn't that good , but maybe this can help, But again, I've tried your suggestinos, but none of them worked !


... :D


I'll keep trying myself to , but Maybe you come up with something different , now you know, what I want to get .

I think there's something wrong with the $id
but maybe it's just me who tries to get something that isn't possible or maybe misunderstood the tutorial or something ...

ty

Edited by Ripix, 14 September 2005 - 08:28 AM.


#8 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 14 September 2005 - 03:30 PM

$result = mysql_query("SELECT * FROM table WHERE id = ".$_GET['id']) or die(mysql_error());
According to what you said, this should work perfectly (or the code i posted before this).

#9 Ripix

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 15 September 2005 - 09:59 AM

pff well...


I'm gettin crazy, now he recognizes the id, but ...

the same error again , read it carefuly:

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 'table WHERE id = 1' at line 1

it says id=1 ... so it recognizes the id, but what's the right syntax??


this is what I have now

<?php 

include("config.php");


$result = mysql_query("SELECT * FROM table WHERE id = ".$_GET['id']) or die(mysql_error()); 
while ($myrow = mysql_fetch_array($result))
echo "Name: ".$myrow["name"]; 
echo "<br>creator: ".$myrow["creator"]; 
echo "<br>resolution: ".$myrow["resolution"]; 
echo "<br>Size: ".$myrow["size"]; 
echo "<br>date: ".$myrow["date"]; 
?>


sorry guys !
;)

#10 Ripix

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 15 September 2005 - 10:54 AM

the problem is solved guys


I had to use this : `
while I was using this : '



this is the code now:


<?php 

include("config.php");

$id = $_GET['id'];

$result = mysql_query("SELECT * FROM `table` WHERE id = '$id'") or die(mysql_error());
while ($myrow = mysql_fetch_array($result))
echo "Name: ".$myrow["name"]; 
echo "<br>creator: ".$myrow["creator"]; 
echo "<br>resolution: ".$myrow["resolution"]; 
echo "<br>Size: ".$myrow["size"]; 
echo "<br>date: ".$myrow["date"]; 
?>


thx anyway ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users