RAH Posted August 17, 2007 Share Posted August 17, 2007 Hello, I was trying to figure out why one of my scripts was failing and by using an "or die" statement for the SQL narrowed it down to this bit of code: $md5 = md5_file("swf/" . basename($jpg_link)); $dupe = mysql_result(mysql_query("select count(gId) from games where gSwfFile='$md5.swf"), 0); if(!empty($dupe)) { continue; } This is giving the following error - "Warning: mysql_result(): supplied argument is not a valid MySQL result resource" The thing is, I've checked that SQL query by running other values in place of $md5 through it and it appears to be fine. select count(gId) from games where gSwfFile='Flat War july 30th 2007.swf'; Any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 17, 2007 Share Posted August 17, 2007 gSwfFile='$md5.swf") should be gSwfFile='$md5.swf'") Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 17, 2007 Share Posted August 17, 2007 Also the variable name "$md5.swf". Are variable allowed to have "." in between?!!!! Quote Link to comment Share on other sites More sharing options...
RAH Posted August 17, 2007 Author Share Posted August 17, 2007 AndyB - Actually my code appears to be as you stated, not sure why it turned out differently when I pasted it here. GuiltyGear - How do I rectify this? I recall doing so before but can't quite remember! Thanks. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 17, 2007 Share Posted August 17, 2007 isnt it supposed to be gSwfFile='$md5.swf'...... Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 try this $md5 = md5_file("swf/" . basename($jpg_link)); $SQL = "select count(gId) from games where gSwfFile='$md5.swf';"; $result = mysql_query($SQL) or die(mysql_error()); $dupe = mysql_result($result , 0); just broke it down really Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 phpSensei - no, that breaks the syntax. MadTechie - Hmm, that displays "No database selected" error. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 18, 2007 Share Posted August 18, 2007 Oh I see What You ment now... Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 18, 2007 Share Posted August 18, 2007 try this $md5 = md5_file("swf/" . basename($jpg_link)); $link = mysql_connect("host", "user", "passw"); mysql_select_db("database", $link); $SQL = "select count(gId) from games where gSwfFile='$md5.swf';"; $result = mysql_query($SQL) or die(mysql_error()); $dupe = mysql_result($result , 0); Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 OK, My code stands as follows: $md5 = md5_file("swf/" . basename($jpg_link)); $link = mysql_connect("localhost", "arcadeh_guser", "REMOVED"); mysql_select_db("arcadeh_gsdb", $link); $SQL = "select count(gId) from games where gSwfFile='$md5.swf';"; $result = mysql_query($SQL) or die(mysql_error()); $dupe = mysql_result($result , 0); if(!empty($dupe)) { continue; } This gives the following error: Query was empty Query: Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 18, 2007 Share Posted August 18, 2007 Couple of small changes. Change: $md5 = md5_file("swf/" . basename($jpg_link)); to: $md5 = md5_file("swf/" . basename($jpg_link)). ".swf"; And change: $SQL = "select count(gId) from games where gSwfFile='$md5.swf';"; $result = mysql_query($SQL) or die(mysql_error()); to: $SQL = "select count(gId) from games where gSwfFile='$md5'"; $result = mysql_query($SQL) or die(mysql_error(). " with query ". $SQL); Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 I've made those changes and the error persists. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 18, 2007 Share Posted August 18, 2007 can you echo $SQL; can see what you get also mysql_select_db("arcadeh_gsdb", $link) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 select count(gId) from games where gSwfFile='f81007a2b78ab8fcb43d132bbed3f1c2.swf'Query was empty Query: Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 Hmm - that is the correct output actually as that value should indeed return empty. Yet the script is ending there despite the following code. Hmm - that is the correct output actually as that if(!empty($dupe)) { continue; } Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 18, 2007 Share Posted August 18, 2007 Query was empty is an error. The reason why, is that SQL is a reserved word - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html - sorry I didn't spot that before. Instead of using $SQL as your query string, change it to $query or anything but a reserved word. Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 OK, I changed it to the following and the error remains: $link = mysql_connect("localhost", "arcadeh_guser", "062688"); mysql_select_db("arcadeh_gsdb", $link); $query = "select count(gId) from games where gSwfFile='$md5'"; $result = mysql_query($query) or die(mysql_error(). " with query ". $query); $dupe = mysql_result($result , 0); echo $query; if(!empty($dupe)) { continue; } Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 18, 2007 Share Posted August 18, 2007 change $dupe = mysql_result($result , 0); to $dupe = mysql_result($result , $link); Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 Upon making those changes I now get the following error: Warning: mysql_result(): Unable to jump to row 5 on MySQL result index 16 in /home/arcadeh/public_html/images.php on line 286 select count(gId) from games where gSwfFile='4047fd968177ff50fb30a873dd35fd0b.swf'Query was empty Query: Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 18, 2007 Share Posted August 18, 2007 can you post line 286 of /home/arcadeh/public_html/images.php Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 $dupe = mysql_result($result , $link); Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 18, 2007 Share Posted August 18, 2007 well this works for me <?php $link = mysql_connect("localhost", "####", "###"); mysql_select_db("###", $link); $query = "select count(ID) from TestTable where Weight ='100g'"; $result = mysql_query($query) or die(mysql_error(). " with query ". $query); $dupe = mysql_result($result, 0); print_r($dupe); if(!empty($dupe)) { // continue; } Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 It appears that even if I comment that section out the error still remains. The only other SQL query in the script is this: { $query2 = mysql_query('INSERT INTO games (gName, gDescription, gSwfFile, gInCategory, gVisible, gOrder, gWidth, gHeight, description2, des2, sponsor_name, sponsor_link, filetype, gThumb, gId, gPlays, playstoday)' . ' values (\' . addslashes($title) . "\', \'" . addslashes($descr) . "\', \'" . addslashes($md5) . "\', \'1\', \'1\', \'0\', \'300\', \'350\', \'\', \'\', \'\', \'\', \'1\', \'$md5.png\', \'999999\', \'\', \'\')'); mysql_query($query2) or die(mysql_error().'<br /><br />Query:'.$query2); } Does the issue lie with that? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 18, 2007 Share Posted August 18, 2007 change to <?php $query2 = mysql_query("INSERT INTO games (gName, gDescription, gSwfFile, gInCategory, gVisible, gOrder, gWidth, gHeight, description2, des2, sponsor_name, sponsor_link, filetype, gThumb, gId, gPlays, playstoday) values ('".addslashes($title)."', '".addslashes($descr)."', '".addslashes($md5)."', '1', '1', '0', '300', '350\', '', '', '', '', '1', '$md5.png', '999999', '', '')"); mysql_query($query2) or die(mysql_error().'<br /><br />Query:'.$query2); ?> Quote Link to comment Share on other sites More sharing options...
RAH Posted August 18, 2007 Author Share Posted August 18, 2007 That doesn't work either. Query was empty Query: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.