【问题标题】:PHP:Issue with form submit [closed]PHP:表单提交问题[关闭]
【发布时间】:2013-02-22 06:32:44
【问题描述】:

我的页面中有一个表格,表格的每一行都有每种商品的一些值,并且在该行的最后一列中,我有“编辑”按钮,它将数据发送到其他一些 php 页面。

为此,使用下面的 (PHP) FORM 并尝试在同一页面本身上发布值。我的问题是我无法检索下面评论语句中给出的值。

如果我只使用 HTML 表单,它工作得很好,但我不想使用,因为表格非常大,可以在资源管理器页面的“查看代码”中轻松看到信息,而且信息很少保密。所以想只使用 PHP 表单。

下面是我的代码。

<FORM METHOD="post" ACTION="inventory.php">
    <?php '<input name="number" type="hidden" id="number"  value="'. $list[$i] .'">'?>
    <?php '<input name="model" type="hidden" id="model"  value="'.$model[$i].'"> '?>
    <?php '<input name="details" type="hidden" id="details"  value="'. $detail[$i].'">'?>
    <?php '<input name="type" type="hidden" id="type" value="'.$type[$i].'">'?>
    <?php echo '<button type="submit" class="button" value="'.$list[$i] .'" name="edit">Edit</button>';?> </FORM> 

if (isset ($_POST['edit']))  
{
    echo $_POST['edit'];               // Able to retrieve value of number (In chrome explorer), In (IE) it just displays as 'Edit'
    echo $_POST['number'];             // Not able to retrieve any value for this
    echo $model=$_POST['model'];       // Not able to retrieve any value for this
    echo $details=$_POST['details'];   // Not able to retrieve any value for this
    echo $type=$_POST['type'];         // Not able to retrieve any value for this
}

【问题讨论】:

  • 对不起,你得回去开始了解php是如何工作的。你问的没有任何意义。 PHP 是一种生成 html 的语言,这是在浏览器中呈现表单的唯一方法。因此,无论您是使用 html(编辑器)还是 php(脚本)创建该 html 表单,都没有任何区别。了解 php 是什么以及它的作用!
  • 没有 PHP Only 表单的概念,如果一个视图的来源,即使您当前的表单也可以在浏览器中看到。一天结束时,无论您在后端使用哪种编程语言,它都必须将输出转换为 HTML,所以我建议不要让您遵循仅 PHP 的表单概念使事情复杂化
  • $list 是在哪里定义的?

标签: php forms post submit


【解决方案1】:

你的输入框还没有echo,怎么渲染

例如 你应该写

<?php echo '<input name="number" type="hidden" id="number"  value="'. $list[$i] .'">'; ?>

而不是

 <?php '<input name="number" type="hidden" id="number"  value="'. $list[$i] .'">'?>

【讨论】:

  • +1 用于指出错误。还要添加一些带有解释的代码。
【解决方案2】:
<form method="post" action="inventory.php">
    <input name="number" type="hidden" id="number"  value="<?php echo $list[$i]; ?>">
   <input name="model" type="hidden" id="model"  value="<?php echo $model[$i];?>"> 
   <input name="details" type="hidden" id="details"  value="<?php echo $detail[$i]; ?>">
    <input name="type" type="hidden" id="type" value="<?php echo $type[$i]; ?>">
    <input type="submit" class="button" value="Edit" name="edit">
 </form> 

if (isset ($_POST['edit']))  
{
echo $_POST['number']; //Not able to retrive any value for this
echo $model=$_POST['model'];//Not able to retrive any value for this
echo $details=$_POST['details'];//Not able to retrive any value for this
echo $type=$_POST['type'];//Not able to retrive any value for this
}

真的,你应该从头开始学习php。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-10
    • 2015-10-08
    • 2020-06-08
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多