onyxblack Posted November 14, 2008 Share Posted November 14, 2008 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! Link to comment https://forums.phpfreaks.com/topic/132663-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/ Share on other sites More sharing options...
zenag Posted November 14, 2008 Share Posted November 14, 2008 while($fetchip = mysql_fetch_array( $ip )) ...will fetch values in array try this... $fetchip = mysql_fetch_row( $ip ); echo $fetchip[0]; Link to comment https://forums.phpfreaks.com/topic/132663-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-689952 Share on other sites More sharing options...
onyxblack Posted November 14, 2008 Author Share Posted November 14, 2008 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 Link to comment https://forums.phpfreaks.com/topic/132663-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-689959 Share on other sites More sharing options...
zenag Posted November 14, 2008 Share Posted November 14, 2008 $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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/132663-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-689964 Share on other sites More sharing options...
onyxblack Posted November 14, 2008 Author Share Posted November 14, 2008 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! Link to comment https://forums.phpfreaks.com/topic/132663-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-689966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.