I am new to PHP and mysql and would greatly appreciate your help.
I am trying to learn PHP and mysql so I decided to create a project to help me do so. I created a registration form that post data to different tables in mysql database.
My form contains a dropdown menu. I was able to post all the items from my form to the mathcourse table in mysql database but not from my dropdown menu.
What I would like to achieve is that if a selection is
made from my form then all the information should go to a particular table.
I have two tables: mathcourse and chemcourse. If math is selected, then the user information should go to the
'mathcourse' table. If chem is selected, then the user information should go to the 'chemcourse' table. Please help
Below is my html form:
Expand|Select|Wrap|Line Numbers
- <form action='register.php' method='POST'>
- FName: <br />
- <input type="text" name="FName" size ="40"><br />
- LName:<br />
- <input type="text" name="LName" size ="25"><br />
- Course:<br />
- <select name ="Course">
- <option value ="" </option><br />
- <option value ="Math" size ="40">Math</option><br />
- <option value ="Chem" size ="40">Chem</option>
- </select><br />
- Phone:<br/>
- <input type="text" name="Phone" size ="20"><br />
- Email:
- <input type="text" name="Email" size ="60"><br />
- submit:
- <input type="submit"name ="submit"/>
Here is the code for register.php page
Expand|Select|Wrap|Line Numbers
- <?php
- define('DB_NAME',"Colstudents");
- define('DB_USER',"root");
- define('DB_PASSWORD', "");
- define('DB_HOST',"localhost");
- $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);//store connection into a variable
- if(!$link) {
- die('could not connect: ' . mysql_error());
- }
- mysql_select_db(DB_NAME, $link);
- if(!$link) {
- die("can\'t use" . DB_NAME . ':' . mysql_error());
- }
- echo 'connected sucessfully';
- $selectcourse ='Course';
- if (option value == 'math'); $_POST mathcourse['Course'];
- else (option value == 'chem'); $_POST chemcourse['Course'];
- //store data into our dabase
- $FName =$_POST['FName'];
- $LName =$_POST['LName'];
- $Course =$_POST['Course'];
- $Phone =$_POST['Phone'];
- $Email =$_POST['Email'];
- $submit = $_POST['submit'];
- $date = date("Y-m-d");
- $sql2 ="INSERT INTO mthcourse SET FName='$FName', LName= '$LName', Course = '$Course', Phone = '$Phone', Email = '$Email', Date = '$date'";
- $result=mysql_query($sql2);
- //if(!//mysql_query) {
- // di//e('Error: ' .mysql_error());
- //}
- mysql_close();
- ?>