this is my first question posted on the internet ever, I was usually able to find some sort of a solution, but now I'll either have to do this some other more basic way or, as I hope get help from someone on Stack Overflow. I have an idea how to do it another way but I would really like if I can make it work like this.
I am trying to build an internet application through which people or organizations would be able to inform the shelter about the clothes they would like to donate to be picked up by shelter's mobile team.
I'm now putting a simplified version of my HTML form, PHP script, JavaScript function, and mySQL used to make the tables in which I want to store the info from the HTML form.
HTML form:
<form action="apply.php" method="post">
<p>Please enter your personal info so we can make contact with you:<br />
Name: <input type="text" name="name" /><br />
Address: <input type="text" name="addr" /><br />
Phone: <input type="text" name="phon" /><br />
e-mail: <input type="text" name="emai" /><br /><br />
<!--previous part of the form needs to be entered only once in a table named
"application" in real form there are more fields-->
<div id="dod">
<p><b>I wish to donate:</b> (in case you wish to donate more stuff click on
"Add more"):</p>
<p> <select name="kind">
<option value="Jacket">Jacket</option>
<option value="Shirt">Shirt</option>
<option value="Pants">Pants</option>
</select></p>
<!--there are more options in the actual form-->
<p>How many items of this type would you like to donate?
<input type="text" name="piec"></p>
<p>Size of the items: <select name="size">
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="Other">Other</option>
<option value="Various">Various</option>
</select></p><br />
<!--This part should be entered several times depending on how many types of clothes
and in which sizes people wish to donate. There are more options in actual form-->
</div>
<center>
<a href="#" onclick="JavaScript:addClothes()" style="font-family: 'verdana'">Add more
</a><br /><br />
<input type="submit" value="Submit"></input>
</center>
</form>
This is simplified version of JavaScript which adds form fields into
function addClothes() {
document.getElementById('dod').innerHTML+="<p><select name='kind'><option\n\
value='Jacket'>Jacket</option>\n\
<option value='Shirt'>Shirt</option>\n\
<option value='Pants'>Pants</option>\n\
</select>\n\
</p><p>How many items of this type would you like to donate? <input type='text'\n\
name='piec'></p>
<p>Size: <select name='size'><option value='S'>S</option>\n\
<option value='M'>M</option>\n\
<option value='L'>L</option>\n\
<option value='Other'>Other</option>\n\
<option value='Various'>Various</option></select></p><br />";
}
These are mySQL expression used to create tables in the shelter_db databse:
CREATE TABLE shelter_db.application
(
Name varchar(80) NOT NULL,
Address varchar(80) NOT NULL,
Phone varchar(20) NOT NULL,
Email varchar(50) NOT NULL,
Stamp timestamp NOT NULL,
PRIMARY KEY (Stamp)
);
CREATE TABLE shelter_db.clothes
(
Kind varchar(40) NOT NULL,
Pieces integer(6) NOT NULL,
Size varchar(20),
Stamp timestamp,
FOREIGN KEY (Stamp)
REFERENCES application (Stamp)
);
My idea is for the data from these two tables to be connected by the timestamp when the records were made, since there most certainly wouldn't be simultaneous entries by different parties. The person assigned to contact donors could then see what that particular party wishes to donate and can send a mobile team with a car or a pickup truck accordingly.
What I'm struggling with is how to formulate the php/sql page, and after going through dozens of web pages I couldn't find one solution that would fit my needs. I'm assuming that I should use implode function but after trying various solutions I wasn't able to find the right one. Here is the code:
<?php
$con = mysql_connect('localhost','root','');
if (!$con) {die('Unable to connect: ' . mysql_error());}
mysql_select_db('shelter_db', $con);
//the following part needs only one entry into application table of the db
$sql="INSERT INTO application (Name, Address, Phone, Email, Stamp)
VALUES
('$_POST[name]','$_POST[addr]','$_POST[phone]','$_POST[emai]',time());
//the following part needs multiple entries depending on how many times the Add more
//button in the HTML form has been clicked
INSERT INTO clothes (Kind, Pieces, Size, Stamp)
VALUES
('$_POST[kind]','$_POST[piec]','$_POST[size]',time())";
if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }
else {
echo 'Database entry successful.';
}
mysql_close($con)
?>
I would be grateful to anyone who could offer me the code that would fit my example. Sorry for the longer post but they said to be thorough. Thanks in advance.