mysql如何插入多个字段

发布于 2024-11-16 11:17:47 字数 3442 浏览 0 评论 0原文

你好,我正在尝试提交一个网络表单并将数据插入到 mysql 中。我遇到的问题是我已将字段设置为具有多个输入框。例如,我不仅仅是“名字”,还有“名字”、“姓氏”,并且我的地址被分为许多字段,以确保最终用户不会错过其地址的某些部分。

我遇到的问题是我无法将这些多个字段提交到 mysql 中。如果我想简单地提交“姓名”字段,我可以,但不能提交名字+姓氏。更清楚地说,我有一个名为“name”的列,我希望“firstname”和“lastname”都存储在那里。地址也是一样。

这是我的 html 代码

<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>

,我的 PHP 变量如下:

$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肥爪爪 2024-11-23 11:17:47
$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'];
$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'];
初熏 2024-11-23 11:17:47

理想情况下,您需要重新设计表,但为了使其适用于现有架构,您需要序列化和反序列化数据。请参阅

http://php.net/manual/en/function.serialize.php

因此,在名称列中,您存储类似 {firstname:lastname} 的内容

$name[0] = $firstname;
$name[1] = $lastname;
$ser = serialize($name); \\--->put this in db

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文