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

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
jenny
Forum Newbie
Posts: 6
Joined: Wed May 12, 2004 10:08 am
Location: KL, Malaysia

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

Post 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);





?>
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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?
jenny
Forum Newbie
Posts: 6
Joined: Wed May 12, 2004 10:08 am
Location: KL, Malaysia

Post 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...
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

backtick is legit table name quoting character.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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!
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post 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) :)
Post Reply