Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

How do I find if an Event ID exists in the database?

Codes here !

Moderators: macek, egami, gesf

How do I find if an Event ID exists in the database?

Postby RichGags » Thu May 10, 2012 3:10 pm

I am new to php coding. I have a database with Event ID's.

When my customer comes to my page, I would like to ask them to enter their Event ID to get started. Im thinking a simple form. On submit, I need to check if the Event ID they enter exists in the database. If it does, send them to one url and if it does not, send them to another.

How would I do this?

Thanks,
Rich
RichGags
New php-forum User
New php-forum User
 
Posts: 7
Joined: Thu Feb 17, 2011 9:54 am

Re: How do I find if an Event ID exists in the database?

Postby Nullsig » Fri May 11, 2012 7:10 am

So if you use a form with a method of POST to submit the data you will have code like this:


Code: Select all
/*
connect to your database here
*/


if(!empty($_POST['eventID'])){//check that they actually entered date
      //check for the existance of the event
     $query = "SELECT * FROM events WHERE eventID = '" . mysql_real_escape_string($_POST['eventID'] . "'"; //this will pull all records that that eventID, the mysql_real_escape_string is to prevent injection

     if($rs = mysql_query($query)){
             //query successful lets see if any records were returned
             if(mysql_num_rows($rs) > 0){
                     //success the event exists
                     header("Location: validEvent.php");
                     exit();
             }else{
                      //failure the event doesn't exist
                     header("Location: invalidEvent.php");
                     exit();
             }
     }else{
           //query failed probably just send them to the invalid eventID page
           header("Location: invalidEvent.php");
           exit();
     }


}else{
    //send them to the "invalid" eventID page
    header("Location: invalidEvent.php");
    exit();
}

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: How do I find if an Event ID exists in the database?

Postby RichGags » Sun May 13, 2012 5:30 pm

Wow. Thanks a million!
RichGags
New php-forum User
New php-forum User
 
Posts: 7
Joined: Thu Feb 17, 2011 9:54 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron