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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.