annii Posted January 25, 2008 Share Posted January 25, 2008 Hello all, I really do hope that this is not too much of a newbie question. I have a MySQL database set up. Within it, I have created a table with the following fields: id, email, name, jobtitle, company, phone, country I want to create a short form that looks up the email address, checks if it's in the database, if it is, (and based on radio button a b or c selection) then it will send the user to page a, b or c respectively. If it is not, then it would send the user to page a2, b2 or c2 respectively. (Now, creating the form I can do!) My problem is how to write the query. I have read (but not necessarily understood!) some php faq for newbies (and performed numerous google searches). I can work out how to connect to the database. I can see that I need some kind of select statement like this (but I know the end bit is wrong as email needs to equal form input value and I'm not sure how to say that):- $result= $xxx->db->query('SELECT email FROM tablename WHERE email= '?'); But then I just get really stumped. I found this in one of the faq ares I visited: $a = “b”; if($a == “a”){ //do something }elseif($a == “c”){ //do something }else{ echo “$a isn’t a or c”; } I can see it might help form the basis of what I want to do, but I just don't have the knowledge to build on it yet. Can any kind person give me some guidance on this please? Thanks Anni Link to comment https://forums.phpfreaks.com/topic/87740-query-db-from-form-input-if-match-then-go-to-page/ Share on other sites More sharing options...
irvieto Posted January 26, 2008 Share Posted January 26, 2008 hello anni, Well I guess you know how the receive data from a html form. Now you have to save the wanted form value into a variable $html_radio = $_POST['radio_input']; then you can construct the sql query and perform it: $sql = "select email from tablename where email='".$html_radio." ' "; $result = $db->query($sql); $num_rows = $db->query_num_rows($result); //im guessing... just detect number of rows from result.. if( $num_rows ==0 ){ # Email is not in the table.. , so redirect him to a2,b2,c2...whatever } elseif( $num_rows>0 ){ # Email IS in the table. do something or redirect him to another page... } Hope this helps.. Link to comment https://forums.phpfreaks.com/topic/87740-query-db-from-form-input-if-match-then-go-to-page/#findComment-449538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.