Interview Question in Sql Server Views


 

Interview Question :: PHP coding question


$imgres = mysql_db_query("database", "select ID, URL1 from contacts where ID=$idno;");
$imgdata = mysql_fetch_row($imgres);
echo mysql_error();
?>

<p align="center"> <img border="1" src="<?php echo $imgdata[1]; ?>" alt="appropriate alt" />
</p>

This code doesn't seem to work....I've tried everything....here's the error messages I'm getting when trying to view it in the browser....

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/nethinga/public_html/Unt... on line 8
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 '' at line 1

What I really don't understand, is that it worked earlier, and I messed with it and now it doesn't. I'm SOOOO FRUSTRATED with this....please help!@!@!@
Answers to "PHP coding question"
RE: PHP coding question?

First off I'm going to suggest you look here http://uk2.php.net/manual/en/function.my...

says that the function is depreciated.



It also looks like you have a semi colon that shouldn't be there



"select ID, URL1 from contacts where ID=$idno;<- (not sure that should be there)");



hope it helps



for eg



$sql = "INSERT

INTO users (reg_username,

reg_password,

reg_email)

VALUES ('bad_guy', 'mypass', ''), ('good_guy',

'1234',

'shiflett@php.net')"; ?>



taken from http://phpsec.org/projects/guide/3.html
 
Vote for this answer ::  
RE: PHP coding question?

Well, mysql_db_query is deprecated (going out of use). Use mysql_connect, and then mysql_query. Make sure the variable $idno is correct, you can hardcode it yourself and see if it works that way. (I.e, try "select ID, URL1 from contacts where ID=1" if you know you have a row where ID=1 in your table.)
 
Vote for this answer ::  
RE: PHP coding question?

this isn't a problem with the depreciated function, especially if you are still using PHP 4.x



the problem is in your sql statement. I know the ";" should not be after idno, also, to optimise your code, you should include $idno in quotes (single ' work). Doing this last will make sure that the index is used, often if the quotes are omitted the index is ignored.
 
Vote for this answer ::  
Update Alert Setting