handley Posted January 13, 2011 Share Posted January 13, 2011 Hi, I've got a basic sign up form but I want a drop down list which will list different catergories that relate to different tables which when selected will input the sign up information into that table which was selected from the catergory drop down. This is the signup form <html><head><title>Birthdays Insert Form</title> <style type="text/css"> td {font-family: tahoma, arial, verdana; font-size: 10pt } </style> </head> <body> <table width="300" cellpadding="5" cellspacing="0" border="2"> <tr align="center" valign="top"> <td align="left" colspan="1" rowspan="1" bgcolor="64b1ff"> <h3>Insert Record</h3> <form method="POST" action="test.php"> <? print "Enter Company Name: <input type=text name=company_name size=30><br>"; print "Enter Contact Name: <input type=text name=contact_name size=30><br>"; print "Enter Telephone: <input type=text name=telephone size=20><br>"; print "Enter Fax: <input type=text name=fax size=30><br>"; print "Enter Email: <input type=text name=email size=30><br>"; print "Enter Address: <input type=text name=address1 size=20><br>"; print "Enter Address: <input type=text name=address2 size=30><br>"; print "Enter Postcode: <input type=text name=postcode size=30><br>"; print "Enter Town / City: <input type=text name=town_city size=20><br>"; print "Enter Website: <input type=text name=website size=30><br>"; print "Enter Company Type: <select name='table'> <option>stationary</option><option>reception</option></select><br>"; print "<br>"; print "<input type=submit value=Submit><input type=reset>"; ?> </form> </td></tr></table> </body> </html> This is the part which I can't figure out and is probably totally wrong! Im trying to use this script to sort the drop down list to then run the correct script to insert the form data. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Hello!</title> </head> <body> <?php if($_POST['table']=='stationary' 'birthdays_insert_record.php') else if($_POST['table']=='reception' 'insert_reception.php') ?> </body> </html> This is the script which works! that inserts the form data into a specific table <html><head><title>Birthdays Insert Record</title></head> <body> <? /* Change db and connect values if using online */ $company_name=$_POST['company_name']; $contact_name=$_POST['contact_name']; $telephone=$_POST['telephone']; $fax=$_POST['fax']; $email=$_POST['email']; $address1=$_POST['address1']; $address2=$_POST['address2']; $postcode=$_POST['postcode']; $town_city=$_POST['town_city']; $website=$_POST['website']; $db="myflawlesswedding"; $link = mysql_connect('localhost', 'root' , ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); $result=mysql_query("INSERT INTO reception (company_name, contact_name, telephone, fax, email, address1, address2, postcode, town_city, website) VALUES ( '$company_name', '$contact_name', '$telephone', '$fax', '$email', '$address1', '$address2', '$postcode', '$town_city', '$website')") or die("Insert Error: ".mysql_error()); mysql_close($link); print "Record added"; ?> <form method="POST" action="birthdays_insert_form.php"> <input type="submit" value="Insert Another Record"> </form> <br> <form method="POST" action="birthdays_dbase_interface.php"> <input type="submit" value="Dbase Interface"> </form> </body> </html> I hope somebody can help me out here! or can point me in a better way to sort this problem! Thanks for any advice! Quote Link to comment https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/ Share on other sites More sharing options...
QuickOldCar Posted January 13, 2011 Share Posted January 13, 2011 Try from this: <?php if($_POST['table']=='stationary' 'birthdays_insert_record.php') else if($_POST['table']=='reception' 'insert_reception.php') ?> To this: <?php if($_POST['table']=='stationary') { include('birthdays_insert_record.php'): } elseif ($_POST['table']=='reception') { include('insert_reception.php'); } else { echo "Nothing was inserted"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/#findComment-1159014 Share on other sites More sharing options...
handley Posted January 13, 2011 Author Share Posted January 13, 2011 I've changed the code but im getting a parse error on this line include('birthdays_insert_record.php'): Ive checked to see if the filename is correct which it is in all files. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/#findComment-1159022 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 That's a colon at the end instead of a semicolon . . . Quote Link to comment https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/#findComment-1159024 Share on other sites More sharing options...
QuickOldCar Posted January 13, 2011 Share Posted January 13, 2011 Ha, so it is, good eye. Corrected: <?php if($_POST['table']=='stationary') { include('birthdays_insert_record.php'); } elseif ($_POST['table']=='reception') { include('insert_reception.php'); } else { echo "Nothing was inserted"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/#findComment-1159026 Share on other sites More sharing options...
handley Posted January 13, 2011 Author Share Posted January 13, 2011 Works perfectly!! Thanks alot for the help, its much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/224338-selecting-table-from-a-dropdown-list/#findComment-1159046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.