Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/65523-solved-script-breaking-on-mysql_result/
Share on other sites

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

 

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

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:

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

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.

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;
}

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:

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;
}

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?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.