Jump to content

Resource id #6 error


willwill100

Recommended Posts

ok, ive ammended my code but i still get a negative result:

[code]////if their name does not already exist in the REAL table, insert it////
$q = "SELECT COUNT(*) FROM `$compl` WHERE `Sail Number`='$snum'";
echo ("<pre>" . $q . "</pre>");
$rs = mysql_query($q) or die('Problem with query: ' . $q . '<br>' . mysql_error());

if (mysql_fetch_assoc($rs)==0){
    $b = "INSERT INTO `$compl` ( `Name` , `Sail Number` , `Class`) VALUES ( '$name', '$snum', '$boattype')";
  
}else{
echo ("<br>No user updated!");
}[/code]

I have inputted $q into phpmyadmin and a value of "0" is returned, why then is the "if statement" taken to be false and "No user updated!" outputted??
Link to comment
https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19441
Share on other sites

[!--quoteo(post=357078:date=Mar 21 2006, 08:31 PM:name=WillWill)--][div class=\'quotetop\']QUOTE(WillWill @ Mar 21 2006, 08:31 PM) [snapback]357078[/snapback][/div][div class=\'quotemain\'][!--quotec--]
okay that makes sense but i still get the error.

any ideas, im really stuck on how to get my table to check if there is already a user in it and enter one if the user is not in the table.....
[/quote]

[code]<?php

$q = "SELECT COUNT(*) FROM `$compl` WHERE `Sail Number`='$snum'";

$result = mysql_query($q);

    if ( mysql_num_rows($query) == 0 ) {
        $q2 = "INSERT INTO `$compl` ( `Name` , `Sail Number` , `Class`) VALUES ( '$name', '$snum', '$boattype')";
        mysql_query($q2);
    }

//more code here or whatever

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19450
Share on other sites

why not just do this

[code]////if their name does not already exist in the REAL table, insert it////
$q = "SELECT * FROM `$compl` WHERE `Sail Number` = '$snum'";
$rs = mysql_query($q) or die('Problem with query: ' . $q . '<br>' . mysql_error());
  $num_rows = mysql_num_rows($rs);
if ($num_rows == 0){
    $b = "INSERT INTO `$compl` ( `Name` , `Sail Number` , `Class`) VALUES ( '$name', '$snum', '$boattype')";
  
}else{
echo ("<br>No user updated!");
}[/code]

Ray
Link to comment
https://forums.phpfreaks.com/topic/5438-resource-id-6-error/#findComment-19452
Share on other sites

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.