Page 1 of 1

what wrong's with this coding?????????

Posted: Wed May 12, 2004 10:08 am
by jenny
can anybody help me to solve this problem??? i want list the image using php.. what wrong's for this coding????????


<?php

@ $db = mysql_pconnect('localhost','root');

if (!$db)
{
echo 'Error: no record to database. Please try again later.';
exit;
}

mysql_select_db('mobile');
$query = "SELECT * FROM `images`";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

if(!$num_results)
{
echo 'No user can be found...Please search again!';
exit();
}


printf("<TABLE BORDER WIDTH=\"100%%\">\n");
printf("<TR>

<TD><B>id</B></TD>
<TD><B>sixfourdata</B></TD>


</TR>\n");


while (($row = mysql_fetch_object($result))){

printf("<TR>
<TD>%s</TD>
<TD>%s</TD>

</TR>\n",
$row->imgid, base64_decode($row->sixfourdata));}
printf("</TABLE>\n");
mysql_free_result($result);





?>

Posted: Wed May 12, 2004 10:11 am
by magicrobotmonkey
Step one - post with php tags so someone will read your script:

Code: Select all

<?php
@ $db = mysql_pconnect('localhost','root'); 

if (!$db) 
{ 
echo 'Error: no record to database. Please try again later.'; 
exit; 
} 

mysql_select_db('mobile'); 
$query = "SELECT * FROM `images`"; 
$result = mysql_query($query); 
$num_results = mysql_num_rows($result); 

if(!$num_results) 
{ 
echo 'No user can be found...Please search again!'; 
exit(); 
} 


printf("<TABLE BORDER WIDTH="100%%">\n"); 
printf("<TR> 

<TD><B>id</B></TD> 
<TD><B>sixfourdata</B></TD> 


</TR>\n"); 


while (($row = mysql_fetch_object($result))){ 

printf("<TR> 
<TD>%s</TD> 
<TD>%s</TD> 

</TR>\n", 
$row->imgid, base64_decode($row->sixfourdata));} 
printf("</TABLE>\n"); 
mysql_free_result($result); 
?>
Step two: Are you getting an error? If so, What? If not then whats not working about it?

Posted: Wed May 12, 2004 10:20 am
by jenny
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Apache2\htdocs\qqq\listimages.php on line 15



///it comes out this error.... if i want to upload an images to the php...

Posted: Wed May 12, 2004 10:23 am
by launchcode
Your SQL query is probably invalid. Echo out the mysql_error value to see what caused it, but at a guess your backticks are wrong:

SELECT * FROM `images`

Just use

SELECT * FROM images

and of course - that table does actually exist, right?

Posted: Wed May 12, 2004 10:45 am
by Weirdan
backtick is legit table name quoting character.

Posted: Wed May 12, 2004 10:51 am
by launchcode
Yes - but are commonly confused for quotes and loose translation posted from code to email to forum post (etc etc) so in that regard cause more trouble than they are worth. Without a mysql_error dump it's impossible to tell what is going on anyway!

Posted: Wed May 12, 2004 11:47 am
by dave420
I'd stop using the mysql_pconnect too, as you're leaving the connection open after your script has finished executing (the "p" is for "persitant", which your scripts are not) :)