如何在php中获取输入的值

时间:2013-10-12 04:20:01

标签: php jquery

我正在尝试使用输入的值更新数据库,但是当新图像是使用jquery时输入已更改,所以我想使用php获取输入的值并使用该值更新我的数据库,我已经尝试过了,但到目前为止它只是用0更新行,即使我将$ _POST更改为$ _GET,我该怎样才能解决这个问题呢?

//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'setTeam')  {


        $cid1 = $_POST['s0'];

        $cid2 = $_POST['s1'];

        $cid3 = $_POST['s2'];


$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");



}
<div id="droppable_slots" class="current_team">
                    <div class="slot 1">1</div>
                    <input type="hidden" name="s0" value="">
                    <div class="slot 2">2</div>
                    <input type="hidden" name="s1" value="">
                    <div class="slot 3">3</div>
                    <input type="hidden" name="s2" value="">
                </div>

更新版本:

if (isset($_POST['f']) && $_POST['f'] == 'setTeam')  {


        $cid1 = $_GET['s0'];

        $cid2 = $_GET['s1'];

        $cid3 = $_GET['s2'];


$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");



}
<form id="droppable_slots" name="droppable_slots" method="POST">
            <div class="slot 1">1</div>
            <input type="hidden" name="s0" value="">
            <div class="slot 2">2</div>
            <input type="hidden" name="s1" value="">
            <div class="slot 3">3</div>
            <input type="hidden" name="s2" value="">
        </form>

3 个答案:

答案 0 :(得分:1)

<form id="droppable_slots" name="droppable_slots" method="POST">
                <div class="slot 1">1</div>
                <input type="hidden" name="s0" value="">
                <div class="slot 2">2</div>
                <input type="hidden" name="s1" value="">
                <div class="slot 3">3</div>
                <input type="hidden" name="s2" value="">
            </form>

答案 1 :(得分:0)

  1. 您应该以表格形式包装输入。
  2. 您应该在隐藏输入中设置值。我想你使用jquery。
  3. 代码应如下所示:

    <form method="POST">
                <div class="slot 1">1</div>
                <input type="hidden" name="s0" value="">
                <div class="slot 2">2</div>
                <input type="hidden" name="s1" value="">
                <div class="slot 3">3</div>
                <input type="hidden" name="s2" value="">
            </form>
    

    如果您要使用表单上的按钮提交,请添加<input type="submit">。如果它以其他方式发生 - 那么用js写脚本将提交它。

    你的php脚本看起来是正确的。

答案 2 :(得分:0)

Use form tag and add attribute method="POST"
<form method="POST" name="update" action="">
<div id="droppable_slots" class="current_team">
                    <div class="slot 1">1</div>
                    <input type="hidden" name="s0" value="">
                    <div class="slot 2">2</div>
                    <input type="hidden" name="s1" value="">
                    <div class="slot 3">3</div>
                    <input type="hidden" name="s2" value="">
                </div>
</form>