1

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'];

2 Answers 2

4
$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'];
Sign up to request clarification or add additional context in comments.

6 Comments

And do wrap them in mysql_real_escape_string before passing them to your database. Never trust user input. Little Bobby Tables might come visit..
Good tip @Bing thanks for the amendment, also I personally would keep these data elements separated in my DB for ease of searching etc. it's simpler to concatenate a few parts or search across multiple columns than to break one down (parse) later down the line.
Trim it too! mysql_real_escape_string(trim($_POST['problem']))
thanks a lot that helped! I was trying to figure out how to connect them and initially did it as $_POST['first'.'last']; no wonder it didnt work. lol
how do i use the escape string? is it mysql_real_escape_string = ("$name, $email... etc");?
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.