473,396 Members | 1,734 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,396 software developers and data experts.

how to insert data into different tables selected from combobox

2
i have try this code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $host="localhost"; // Host name
  3. $username="root"; // Mysql username
  4. $password=""; // Mysql password
  5. $db_name="bankofquestions"; // Database name
  6.  
  7. // Connect to server and select databse.
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10.  
  11. if(isset($_POST['select_3']) && $_POST['select_'] == 'chem_v_qn1'){
  12.  
  13. $question = $_POST['question'];
  14.  
  15. $query="Insert into _v_qn1 (question) values ('$question')"; 
  16.  
  17.     mysql_query($query) or die ('error updating database');
  18.  
  19.     echo "database updated with '$question'";
  20.  
  21. }
  22. ?>
Oct 15 '12 #1
3 4459
Rabbit
12,516 Expert Mod 8TB
Just change it from a static table name to the value in your combobox.

But you should be aware that you are wide open for SQL injection attacks. And also, since you are inserting similar data into multiple tables, your database structure is most likely not normalized. There's really not a need to do this.
Oct 15 '12 #2
mbemua
2
I have want to make a combo box in dreamweaver using php and html.After selecting any table from the combo box the user writes his question in text box related to that particular table.In mysql i have made separate tables of every questions mentioned in combo box.Now i want that whenever user press the submit button after selecting the table from combo box the the question he writes in the textbox is inserted to that relevent table for example if table one is selected then the questions in text box should be saved in table one in database.I do not have the code.Any kind of help will be appreciated.
Mar 29 '13 #3
Rabbit
12,516 Expert Mod 8TB
What do you mean you don't have any code? You posted your code in the first post. You just need to implement my suggestion in post 2.

Also, you should be aware that this is not a code writing service. We will help you troubleshoot your code but we are not here to give you code.

And finally, you should not have separate tables for every question. That breaks the rules of normalization and makes it more difficult for you to write queries. As has already been witnessed. So I would suggest that you redesign your tables.
Mar 29 '13 #4

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

Similar topics

9
by: Hi5 | last post by:
Hi, Any Idea how, I can make an Insert statement to insert data into 6 different tables, that are all holding all data of my database? Is there any example? I would be grateful if you could...
4
by: satish | last post by:
Values of two columns in two different tables--presentation using select Hi Everyone, i have two tables in the database . One is called address table and one is adressPhone Table. Below...
0
by: danishce | last post by:
Hello, I want to insert data directly into my windows form data grid and load a combobox(userid) in the 1st column of data grid,a textbox(password) in 2nd column of datagrid. The code for insert...
0
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the...
1
by: ghjk | last post by:
I want to insert data through my web application. I have dropdown box (have 2 values Yes and No)and when i select yes insert record will be 5 and when i select no insert record will be 3. So i cant...
5
by: narendrareddy | last post by:
Hi , assume a flat file name emp.txt contains the following data 10000100001 narendranathreddy tallapireddy 01-01-2007 male 10000100002 ravindranathreddy tallapireddy 01-01-2008 male...
5
by: RomeoX | last post by:
Hi everybody actually I need your help in fixing my code. Actually I have a library system that can be applied in university or any school and I'm stucking in a page that for loan student book. I...
2
by: shivasusan | last post by:
Hi! I have two tables in my database (userinfo, logininfo) - userinfo table has five fields (uname, pws, con_pws, squest, sans) - logininfo table has then six fields (fname,lname,dob,add1,...
0
by: josef gonjales | last post by:
I am using the code below to display selected table in datagrid but when i add one more comobobox and a datagridview and use same code , the second does not write into the table. i want to insert...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.