Jump to content

[SOLVED] mysql_num_rows(): supplied argument is not a valid?


ObscureProtection

Recommended Posts

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

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]

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

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

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.