473,395 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Post drop-down menu selection to different tables in mysql

Hi All,

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
  1.     <form action='register.php' method='POST'>
  2.  
  3.         FName: <br />
  4.  
  5.     <input type="text" name="FName" size ="40"><br />
  6.  
  7.         LName:<br />
  8.  
  9.     <input type="text" name="LName" size ="25"><br />
  10.  
  11.         Course:<br />
  12.  
  13.     <select name ="Course">
  14.     <option value =""  </option><br />
  15.     <option value ="Math"  size ="40">Math</option><br />
  16.     <option value ="Chem"  size ="40">Chem</option>
  17.     </select><br />
  18.  
  19.         Phone:<br/>
  20.  
  21.     <input type="text" name="Phone" size ="20"><br />
  22.  
  23.         Email:
  24.  
  25.     <input type="text" name="Email" size ="60"><br />
  26.  
  27.         submit:
  28.  
  29.     <input type="submit"name ="submit"/>

Here is the code for register.php page

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. define('DB_NAME',"Colstudents");
  5. define('DB_USER',"root");
  6. define('DB_PASSWORD', "");
  7. define('DB_HOST',"localhost");
  8.  
  9. $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);//store connection into a variable
  10.  
  11. if(!$link) {
  12.     die('could not connect: ' . mysql_error());
  13. }
  14.  
  15. mysql_select_db(DB_NAME, $link);
  16.  
  17. if(!$link) {
  18.     die("can\'t use" . DB_NAME . ':' . mysql_error());
  19. }
  20.  
  21. echo 'connected sucessfully';
  22.  
  23. $selectcourse ='Course';
  24.  
  25. if (option value == 'math'); $_POST mathcourse['Course'];
  26.  
  27. else (option value == 'chem'); $_POST chemcourse['Course'];
  28.  
  29.  
  30. //store data into our dabase
  31.  
  32.  
  33. $FName     =$_POST['FName'];
  34. $LName     =$_POST['LName'];
  35. $Course    =$_POST['Course'];
  36. $Phone     =$_POST['Phone'];
  37. $Email     =$_POST['Email'];
  38. $submit = $_POST['submit'];
  39. $date = date("Y-m-d");
  40.  
  41. $sql2 ="INSERT INTO mthcourse SET  FName='$FName', LName= '$LName', Course = '$Course',  Phone = '$Phone', Email = '$Email', Date = '$date'";
  42. $result=mysql_query($sql2);
  43.  
  44. //if(!//mysql_query) {
  45. //    di//e('Error: ' .mysql_error());
  46. //}
  47.  
  48. mysql_close();
  49.  
  50. ?>
Mar 22 '12 #1
2 2433
Dormilich
8,658 Expert Mod 8TB
line #25 & #27 (PHP code) are totally off. that's not how you do a condition or fetching form data (that part should get you a syntax error)
Mar 22 '12 #2
// first get the value of selection from dropdown menu something like this :

Expand|Select|Wrap|Line Numbers
  1. $temp = $_POST['drop_down_menu'];
now make query with if condition like this ::

Expand|Select|Wrap|Line Numbers
  1. if($temp == "math")
  2. {
  3.    $qry = "insert into mathcourse values('','','')";
  4. else
  5. {
  6.    $qry = "insert into chemcourse values('','','')";
  7. }
now execure the query like this :::

Expand|Select|Wrap|Line Numbers
  1. $query = mysql_query($qry) or die(mysql_error());
try it.........

Bharat Parmar(Bharat383)
Apr 16 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Plumer | last post by:
Hello everyone, Yesterday I posted a message about implementing drag & drop in a TreeView control. I'm having real difficulty getting this to work -- the process seems to be incredibly...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
8
by: WindAndWaves | last post by:
Hi everyone, Has anyone got any experience with drop and drag in Access? I would like to make a calendar style form where my users can drop and drag appointments.... I am using Access 2003...
4
by: Dave | last post by:
I need to add the ability to drag from a Windows Form and drop into a non dotNet application. For example, having a generated image in my app that I wish to drag out into explorer as a friendly way...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
0
by: SamSpade | last post by:
I've mentioned in other post that I've implemented Drag/Drop for a RichTextBox and using it clears the undo buffer except for the Drag/Drop undo. I'd love to hear from someone that they have...
5
by: sesar | last post by:
How can I impement drag&drop for simple 'dialog base' application... I want to drag&drop txt file and load the text to variable
0
by: RHSFSS | last post by:
Hi, I have a Drag and Drop registration problem (See http://www.thescripts.com/forum/thread434707.html for similar problem post), can anyone out thereadvise on the best solution? I have a .NET 2.0 ...
5
by: empiresolutions | last post by:
Hello Fellow Developers, I am using the awesome drag and drop script found at http://script.aculo.us/. I have also added a modification that interacts to a db for reordering upon release of a...
9
by: adastic | last post by:
Any idea how this guy does his AJAX drop shadows (see the post title "New Year New Site" in blue with the light gray in larger font offset from it): ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.