Jump to content

Recommended Posts

I am having problems with this if statement takign the wrong branch

 

If the user wants to add a record, i query the database to see if they have less than 3 records in there.  If they have, perform the insert, if they have 3, display the error message to them.

 

I have one record in the database but i am getting shown the error

 

I want to count the number of times the userid occurs in the database and that is what i am using to compare against but it is not working

$result = mysql_query("SELECT COUNT(userid) FROM carshare WHERE userid='".$_SESSION['user_id']."'") or die (mysql_error());

$numrows = mysql_fetch_row($result);

if($numrows < 3) {
    //query to enter form data into database
    $sql = mysql_query("INSERT INTO carshare (userid, seats_available, start_street, start_postcode, start_lat, start_long, end_street, end_postcode, end_lat, end_long, depart_time) 
    	VALUES('$userid', '$seats', '$s_street', '$s_postcode', '$s_lat', '$s_long', '$e_street', '$e_postcode', '$e_lat', '$e_long', '$depart'");    	    

    //if the query didn't complete display error message
    if(!$sql) { 
    	echo "There has been an error adding your carshare. Please contact the webmaster via contact page."; 
    	    }
}
else {
    echo "<h2 class=\"errorhead\">Warning - You are only allowed to add 3 car shares!!</h2>";
}

 

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.