Reputation: 924
Hi I'm trying to submit a webform and insert the data into mysql. The problem I have is that I have setup the fields to have multiple input boxes. For example instead of just "name" I have "first name", "last name" and my address is divided into many fields to ensure the end user does not miss certain parts of their address.
The problem I have is that I can't submit those multiple fields into mysql. If I wanted to simply submit the "name" field I can, but not first name + last name. To be more clear, I have a column named "name" and I want the "firstname" and "lastname" both to be stored there. Same thing with the address.
Here is my html code
<ul>
<li id=name">
<label class="description" for="element_1">Name </label>
<span>
<input id="first" name= "first" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="last" name= "last" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li>
<li id="phone">
<label class="description" for="element_2">Phone </label>
<span>
<input id="parea" name="parea" class="element text" size="3" maxlength="3" value="" type="text" /> -
<label for="parea">(###)</label>
</span>
<span>
<input id="pfirst" name="pfirst" class="element text" size="3" maxlength="3" value="" type="text" /> -
<label for="pfirst">###</label>
</span>
<span>
<input id="plast" name="plast" class="element text" size="4" maxlength="4" value="" type="text" />
<label for="plast">####</label>
</span>
</li>
<li id="email">
<label class="description" for="element_3">Email </label>
<div>
<input id="email1" name="email1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="address">
<label class="description" for="element_4">Address </label>
<div>
<input id="street" name="street" class="element text large" value="" type="text">
<label for="element_4_1">Street Address</label>
</div>
<div>
<input id="element_4_2" name="element_4_2" class="element text large" value="" type="text" />
<label for="element_4_2">Address Line 2</label>
</div>
<div class="left">
<input id="element_4_3" name="element_4_3" class="element text medium" value="" type="text" />
<label for="element_4_3">City</label>
</div>
<div class="right">
<input id="element_4_4" name="element_4_4" class="element text medium" value="" type="text" />
<label for="element_4_4">State / Province / Region</label>
</div>
<div class="left">
<input id="element_4_5" name="element_4_5" class="element text medium" maxlength="15" value="" type="text" />
<label for="element_4_5">Postal / Zip Code</label>
</div>
</li>
</ul>
And my PHP variables are as such:
$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];
Upvotes: 1
Views: 1229
Reputation: 4454
Ideally you need to redesign your table but for making it work with the existing schema, you need to serialize and de-serialize data. see
http://php.net/manual/en/function.serialize.php
So in name column you store something like {firstname:lastname}
$name[0] = $firstname;
$name[1] = $lastname;
$ser = serialize($name); \\--->put this in db
Upvotes: 0
Reputation: 19748
$name=$_POST['first'] ." ". $_POST['last'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];
Upvotes: 4