 |
Page 1 of 1
|
| Message |
|
lt18
nOObee
Joined: 19 Oct 2007
Posts: 2
Location: London 63 Cash
|
 INERT MULTIPLE HTML ELEMENTS INTO A SINGLE MYSQL COLUMN WITH
'INERT MULTIPLE HTML ELEMENTS INTO A SINGLE MYSQL COLUMN WITH PHP'
Dear All
I am trying to process form data with PHP and insert the data into a database. My problem is (1) that I have two '<input>' elements that I want to 'INSERT INTO' one MySQL column (address) of the table 'user_feedback' and (2) I have three '<select>' elements that I want to group together and INSERT INTO another single column (dob) of the same table.
In both scenarios I am able to insert the first named value for example '$_POST[dob]' and '$_POST[address1]' but not the subsequent ones (separated by commas). Does any one know if or how this can be done? Many thanks.
Below is the table I created:
mysql> create table user_feedback (id int not null primary key auto_increment, f
irst_name varchar(50), surname varchar(50), dob varchar(50), sex varchar(7), add
ress varchar(255), postcode varchar(25), email varchar(50), chosen_location varc
har(50), time varchar(50), month varchar(18), date varchar(50), comments varchar
(25));
Below is my php script:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$conn = mysql_connect("elita", "user", "password");
mysql_select_db("feedback", $conn);
$sql = "INSERT INTO user_feedback (first_name, surname, dob, sex, address, postcode, email, chosen_location, time, month, date, comments) VALUES ('$_POST[firstname_1]', '$_POST[surname_1]', '$_POST[dob], [dates1], [months1]', '$_POST[sex]', '$_POST[address1], [address2]', '$_POST[postcode1]', '$_POST[email1]', '$_POST[location]', '$_POST[time]', '$_POST[months]', '$_POST[dates2]', '$_POST[AdditionalComments]')";
if (mysql_query($sql, $conn)) {
echo "record added";
} else {
echo "error - record not added";
}
?>
</body>
</html>
And below are the affected parts of the HTML page which corresond to the problems:
(1):
<input class="contact4" name="address1" type="text" accesskey="f" tabindex="6" value="address" size="40" alt="input address" accept= "The Unicode Standard, Version 3.0" max="max" length="40" />
<input class="contact7" name="address2" type="text" accesskey="g" tabindex="7" value="address" size="40" alt="input address" accept="The Unicode Standard, Version 3.0" max="max" length="40" />
(2)
<select class="contact1"name="dob" size="1" tabindex="10" accesskey="j" value="dob_1">
<option name="0" value="year">year</option>
<option name="1" value="1910">1910</option>
<option name="2" value="1911">1911</option>
<option name="3" value="1912">1912</option>
<option name="4" value="1913">1913</option>
<option name="5" value="1914">1914</option>
<select class="contact2" name="dates1" tabindex="11" accesskey="k" value="dates_1">
<optgroup name="dates1" value="dates_1">
<option name="00_1" value="00b_1">Date</option>
<option name="01_1" value="01b_1">1st</option>
<select class="contact3" name="months1" tabindex="12" accesskey="l" value="months_1">
<optgroup name="months1" value="months_1">
<option name="00a_1" value="00a_1">Month</option>
<option name="jan_1" value="jan_1">January</option>
Thanks in advance for any help!!
_________________ remember, know to forget
|
| Fri Oct 19, 2007 12:46 pm |
|
 |
|
|
pratamishus
Site Admin
Joined: 05 Sep 2006
Posts: 587
Location: Tashkent  1552 Cash
|
Hi! Do not quite understand what you have done, never done anything like this. Though I guess this should work
$sql = "INSERT INTO user_feedback (first_name, surname, dob, sex, address, postcode, email, chosen_location, time, month, date, comments) VALUES ('$_POST[firstname_1]', '$_POST[surname_1]', '$_POST[dob], $_POST[dates1], $_POST[months1]', '$_POST[sex]', '$_POST[address1], $_POST[address2]', '$_POST[postcode1]', '$_POST[email1]', '$_POST[location]', '$_POST[time]', '$_POST[months]', '$_POST[dates2]', '$_POST[AdditionalComments]')";
_________________ www.eb-downloads.com
FREE E-BOOKS DOWNLOADS.
|
| Sun Oct 21, 2007 11:29 am |
|
 |
lt18
nOObee
Joined: 19 Oct 2007
Posts: 2
Location: London 63 Cash
|
Hi!
Thanks for the post - I have tried your suggestion and it works!
For anyone who may look at this later, my initial query was how would 15
HTML 'POST DATA' elements know to go into the 12 MySQL columns available?
There do not seem to be enough columns to go round, below I have listed the HTML
POST DATA elements and MySQL columns:
MySQL Columns:
1 first_name
2 surname
3 dob a
4 sex
5 address b
6 postcode
7 email
8 chosen_location
9 time
10 month
11 date
12 comments
POST DATA
1 '$_POST[firstname_1]'
2 '$_POST[surname_1]'
3 '$_POST[dob]' a
4 '$_POST[dates1]' a
5 '$_POST[months1]' a
6 '$_POST[sex]'
7 '$_POST[address1]' b
8 '$_POST[address2]' b
9 '$_POST[postcode1]'
10 '$_POST[email1]'
11 '$_POST[location]'
12 '$_POST[time]'
13 '$_POST[months]'
14 '$_POST[dates2]'
15 '$_POST[AdditionalComments]'
What I wanted was the three HTML 'POST DATA' elements
marked "a" to go into one MySQL column 'dob' also marked
"a" and the same for those HTML POST DATA elements marked
"b" into the corresponding MySQL column 'address' also
marked "b".
In short I would like to have the HTML POST DATA from the
grouped elements listed (above) 3, 4, and 5 to act as a
whole and go into one MySQL column listed as 1 (dob) and
the same for 7 and 8 listed above to go into the column
listed 5(address).
--
Question answered!!
_________________ remember, know to forget
|
| Mon Oct 22, 2007 2:47 pm |
|
 |
|
|
The time now is Thu Nov 20, 2008 12:17 pm | All times are GMT - 6 Hours
|
Page 1 of 1
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|