Jump to content

Mysql Num Rows error


Bradley99

Recommended Posts

Here's the error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stayway1/public_html/www.one-mafia.com/eng/inboxread.php on line 99

 

Here's lines 90-110: (99 in bold)

 

if (strip_tags($_POST['Accept_OC'])){
$oc_id=strip_tags($_POST['oc_id']);
if (strip_tags($_POST['place']) == "we"){
$use="we_inv";
$a="we";
$query= "SELECT * FROM oc WHERE we_inv='$username' AND id='$oc_id'";
}elseif (strip_tags($_POST['place']) == "ee"){
$use="ee_inv";
$a="ee";
$query= "SELECT * FROM oc WHERE ee_inv='$username' AND id='$oc_id'";

}elseif (strip_tags($_POST['place']) == "driver"){
$use="driver_inv";
$a="driver";
$query= "SELECT * FROM oc WHERE driver_inv='$username' AND id='$oc_id'";
}

$round=mysql_query($query);
[b]$check=mysql_num_rows($round);[/b]
if ($check != "0"){
echo "You are now in that OC";
mysql_query("UPDATE `oc` SET `$a`='$username' WHERE `id`='$oc_id'");
mysql_query("UPDATE `users` SET `oc`='1' WHERE `username`='$username'");
}
}
if (strip_tags($_POST['Yes_street'])){
$race_id=strip_tags($_POST['race_id']);
if ($fetch->street != "0"){ echo "Your in a race."; }elseif ($fetch->street == "0"){

if ($fetch->last_race >= time()){ echo "You cant do anouther race yet."; }elseif ($fetch->last_race < time()){

Link to comment
https://forums.phpfreaks.com/topic/227005-mysql-num-rows-error/
Share on other sites

First, you don't have a default condition, so if none of the if/elseif conditions evaluate to true, the variables won't have values. But anyhow, to help diagnose your problem, add some reporting to the query for debugging. The second error you posted doesn't appear related . . .

 

$round=mysql_query($query) or die( "<br>Query string: $query<br>Failed with error: " . mysql_error() );

First, you don't have a default condition, so if none of the if/elseif conditions evaluate to true, the variables won't have values. But anyhow, to help diagnose your problem, add some reporting to the query for debugging. The second error you posted doesn't appear related . . .

 

$round=mysql_query($query) or die( "<br>Query string: $query<br>Failed with error: " . mysql_error() );

 

Thanks, Here's the error i get...

 

Query string: Resource id #5
Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1

Here's what I believe it comes down to: if none of the if/elseif conditions evaluate to true, the variables won't have new values assigned. If that's the case, and you previously executed a query with $query = mysql_query("SELECT whatever . . .), then $query will still hold that result resource instead of the query string it should hold at that point. To test that, make this change:

 

}elseif (strip_tags($_POST['place']) == "driver"){
$use="driver_inv";
$a="driver";
$query= "SELECT * FROM oc WHERE driver_inv='$username' AND id='$oc_id'";
} 
else { // < --- ADD THIS
     die( "NO CONDITIONS MATCHED."); <--- ADD THIS
} <--- ADD THIS
$round=mysql_query($query);
$check=mysql_num_rows($round);

Ok, Here's the script from where the invite is sent... (well that part of the script...)

 

if (strip_tags($_POST['inv_button'])){
$inv_username=strip_tags($_POST['inv_username']);
$com=mysql_num_rows(mysql_query("SELECT * FROM oc WHERE leader='$inv_username' OR we='$inv_username' OR ee='$inv_username' OR driver='$inv_username'"));
$lee=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$inv_username'"));
if ($lee->last_oc > time()){
echo "This is user is not ready to do an oc!";
}elseif ($lee->last_oc <= time()){
if ($com != "0"){
echo "This person is in an oc!";
}elseif ($com == "0"){
if (strtolower($username) == strtolower($inv_username)){
echo "You cannot invite your self";
}elseif(strtolower($username) != strtolower($inv_username)){

if (strip_tags($_POST['inv']) == "inv_we"){
$inv_username=strip_tags($_POST['inv_username']);
$check = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='$inv_username'"));
if ($check == "0"){
echo "No such user.";
}elseif ($check != "0"){





if ($oc->we != "0"){
echo "You need to kick the Weapons expert before you invite someone else.";
}elseif ($oc->we == "0"){


$invite_text="<form name=invite_to_oc method=post action=?accept=oc&oc_id=$oc->id>
  <div align=center>You have been invited to join $username s Getaway in $lead->location, please 
    choose one of the following options:<br>

    <input name=Decline class=button type=submit id=Decline value=Decline>
    | 
    <input name=Accept_OC type=submit class=button id=Accept value=Accept>
  </div>
</form>"; 

mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` )
VALUES (
'', '$inv_username', '$inv_username', '$invite_text', '$date', '0'
)");
echo "Weapons expert invited";
mysql_query("UPDATE oc SET we_inv='$inv_username' WHERE id='$oc->id'");

 

 

At the top of the script that is doing the processing, add this right after the opening <?php tag so you can see exactly what is being sent to the script.

echo '<pre>$_POST array is: ';
print_r($_POST);
echo '</pre><pre>$_GET array is: ';
print_r($_GET);
echo '</pre>';

Do you mean on the Inbox page? Or the last code i posted which actually send's the mail?

 

Here's what i got on the Inbox page with it...

 

$_POST array is: Array
(
)

$_GET array is: Array
(
    [id] => 34
)


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/stayway1/public_html/www.one-mafia.com/eng/inboxread.php:2) in /home/stayway1/public_html/www.one-mafia.com/eng/inboxread.php on line 7

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.