Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result


onyxblack

Recommended Posts

The folowing is code I know works, (the code I made to test my query's)

<?php

include('incl/login.conf.php');
mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS);
mysql_select_db(MYSQL_DB);

$ip = mysql_query("select ip FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
while($fetchip = mysql_fetch_array( $ip ))
{
echo $fetchip['ip'];
echo "<br>";
}

$posttime = mysql_query("select posttime FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
while($fetchtime = mysql_fetch_array( $posttime ))

echo $fetchtime['posttime'];
echo "win.";
?>

But the moment I try to add the if statement it thow's an error

'Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\work.php on line 10'

 

I'm fairly certin it has to do with both the 'while' statements being so close together, I just dont know how to phrase them...

 

<?php

include('incl/login.conf.php');
mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS);
mysql_select_db(MYSQL_DB);

$ip = mysql_query("select ip FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
while($fetchip = mysql_fetch_array( $ip ))
$posttime = mysql_query("select posttime FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
while($fetchtime = mysql_fetch_array( $posttime ))

if ($fetchip['ip'] != $_SERVER['REMOTE_ADDR'])
{
mysql_query("INSERT INTO timetoclick (ip, posttime) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".time()."')");
echo "New<br>";
}
elseif ($fetchtime['posttime']-43200>time())
{
echo "You have allreact been attacked. You can not be attacked by this person for X";
echo " more seconds.";
}
else 
{
mysql_query("INSERT INTO timetoclick (ip, posttime) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".time()."')");
echo "New<br>";
}

?>

 

Any help would be awesome!

Ok... Well... Its not erroring any more, but its not doing what I want it to do, it currently brings up a blank page when it should execute line 14, I'm so confused by this

... possibly .time(). is the problem?

 

Current code reads

 

<?php

include('incl/login.conf.php');
mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS);
mysql_select_db(MYSQL_DB);

$ip = mysql_query("select ip FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
$fetchip = mysql_fetch_row( $ip );
$posttime = mysql_query("select posttime FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
while($fetchtime = mysql_fetch_array( $posttime ))

if ($fetchip['ip'] != $_SERVER['REMOTE_ADDR'])
{
mysql_query("INSERT INTO timetoclick (ip, posttime) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".time()."')");
echo "New<br>";
}
elseif ($fetchtime['posttime']-43200>time())
{
echo "You have allreact been attacked. You can not be attacked by this person for X";
echo " more seconds.";
}
else 
{
echo "bah";
/*
mysql_query("UPDATE `timetoclick` SET `posttime`='"time()"' WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'");
echo "New<br>";
*/
}

?>

 

and it just brings a blank page... dosn't exicute any of the SQL


$ip = mysql_query("select ip FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
$fetchip = mysql_fetch_row( $ip );
$posttime = mysql_query("select posttime FROM timetoclick WHERE ip='".$_SERVER['REMOTE_ADDR']."'");
$fetchtime = mysql_fetch_row( $posttime );

if ($fetchip[0] != $_SERVER['REMOTE_ADDR'])
{
mysql_query("INSERT INTO timetoclick (ip, posttime) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".time()."')");
echo "New<br>";
}
elseif ($fetchtime[0]-43200>time())
{
echo "You have allreact been attacked. You can not be attacked by this person for X";
echo " more seconds.";
}
else 
{
mysql_query("INSERT INTO timetoclick (ip, posttime) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".time()."')");
echo "New<br>";
}

?>

Thank you so much! - awesome

 

Come check it out when ya have a chance http://bladefight.net - its still gona be a day or so till I get this part of the code up - (using for the unique link)

 

This forum rocks - seems some of the other forums is nothing but flames.

 

Thank you!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.