ObscureProtection Posted October 5, 2007 Share Posted October 5, 2007 I'm getting an: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/op/public_html/test.php on line 70 if(isset($_POST['1']) || isset($_POST['2']) || isset($_POST['3']) || isset($_POST['4']) || isset($_POST['5'])) { if(!empty($_POST['1'])) $user_rating = $_POST['1']; if(!empty($_POST['2'])) $user_rating = $_POST['2']; if(!empty($_POST['3'])) $user_rating = $_POST['3']; if(!empty($_POST['4'])) $user_rating = $_POST['4']; if(!empty($_POST['5'])) $user_rating = $_POST['5']; $ip = safeEntry(trim(getenv("REMOTE_ADDR"))); $date = date('Y-m-d H:i:s'); Line 70: if(mysql_num_rows(mysql_query("select ip from ban where ip='$ip'")) == 0) mysql_query("insert into rate values(null, $entry,'$date', $ip, $user_rating)"); } I don't understand why it's not working...? It's a code for a voting system (1-5 scale). I'm trying to check to see if the voter IP is banned, if it isn't then insert the voting values. PHP version 5.2.3 MySQL version 4.1.22 Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/ Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 are you connecting to the DB with mysql_select_db() ? Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362219 Share on other sites More sharing options...
ObscureProtection Posted October 5, 2007 Author Share Posted October 5, 2007 Yes, I sectioned off the part that was throwing the error, but further above on test.php I have: include "mysqlc.php"; which calls: <?php $host = "blahblah.net"; $data = "thisIsData"; $user = "PHPhelp"; $pass = "help"; $sql = mysql_connect("$host", "$user", "$pass"); $db = mysql_select_db("$data") or die (mysql_error()); ?>[/cod] Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362224 Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 that is not how you use num_rows btw try something like <?php $link = mysql_connect("localhost", "mysql_user", "mysql_password"); mysql_select_db("database", $link); $result = mysql_query("SELECT * FROM table1", $link); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362229 Share on other sites More sharing options...
ObscureProtection Posted October 5, 2007 Author Share Posted October 5, 2007 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/op/public_html/test.php on line 71 <?php $host = "blahblah.net"; $data = "thisIsData"; $user = "PHPhelp"; $pass = "help"; $sql = mysql_connect("$host", "$user", "$pass"); mysql_select_db("$data", $sql); if(isset($_POST['1']) || isset($_POST['2']) || isset($_POST['3']) || isset($_POST['4']) || isset($_POST['5'])) { if(!empty($_POST['1'])) $user_rating = $_POST['1']; if(!empty($_POST['2'])) $user_rating = $_POST['2']; if(!empty($_POST['3'])) $user_rating = $_POST['3']; if(!empty($_POST['4'])) $user_rating = $_POST['4']; if(!empty($_POST['5'])) $user_rating = $_POST['5']; $ip = safeEntry(trim(getenv("REMOTE_ADDR"))); $date = date('Y-m-d H:i:s'); $result = mysql_query("select ip from ban where ip='$ip'", $sql); Line 71: $num_rows = mysql_num_rows($result); if($num_rows == 0) mysql_query("insert into rate values(null, $entry,'$date', $ip, $user_rating)"); } ?> Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362235 Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 <?php $sql = mysql_connect($host, $user, $pass); mysql_select_db($data, $sql); ?> Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362239 Share on other sites More sharing options...
ObscureProtection Posted October 5, 2007 Author Share Posted October 5, 2007 ah, you're right. Fixed it, but it's still throwing the same error. Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362241 Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 you removed the quotes around $pass, $user etc? <?php mysql_query("SELECT 'ip' FROM 'ban' where ip=$ip", $sql);?> Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362242 Share on other sites More sharing options...
ObscureProtection Posted October 5, 2007 Author Share Posted October 5, 2007 yup I did remove the quotes for $pass and $user prior, but it's the '$ip' that did it, ahh thanks so much you're the greatest! Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362245 Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 your welcome please click topic solved Link to comment https://forums.phpfreaks.com/topic/71905-solved-mysql_num_rows-supplied-argument-is-not-a-valid/#findComment-362247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.