Jump to content

[SOLVED] Script breaking on mysql_result


RAH

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
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.