While循环-其他输入中只有一个输入正在通过POST发送值 [英] While loop - Only one input from many others is sending a value through POST

查看:118
本文介绍了While循环-其他输入中只有一个输入正在通过POST发送值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我从称为optionale的表中获取输入名称和值并对其进行以下处理的代码:

 < form role = form autocomplete = off action = includes / functions / fisa-init.php method = POST> 
<?php
connectDB();
$ query = mysqli_query($ mysqli, SELECT * FROM`optionale`)或die(mysqli_error($ mysqli));
while($ row = mysqli_fetch_array($ query))
{
?>
< span><?php echo $ row [’denumire’]; < / span>
< input type = text name = nrBucati>
< input type = hidden value =<?php echo $ row [’cod’];?> name = codProdus>
<?php}?>
< / form>

可选表如下:





HTML看起来像这样:





如上图所示,我使用HTML,输入的名称(取自optionale表)和我在其中写入值的实际输入。



fisa-init.php:

  $ stmt3 = $ mysqli-> prepare( 
更新
`stocuri`
SET
`cantitate` =`cantitate`-?
WHERE`cod` =?
);


$ stmt3-> bind_param( is,$ bucata,$ cod);

//设置参数并执行
$ bucata = mysqli_real_escape_string($ mysqli,$ _POST [’nrBucati']);
$ cod = mysqli_real_escape_string($ mysqli,$ _POST [’codProdus’]);

if(!$ stmt3-> execute())
{
echo Exercuția aîntâmpinato eroare:(。$ stmt3-> errno。) 。 $ stmt3->错误;
}
$ stmt3-> close();

$ mysqli-> close();

在上面的代码(fisa-init.php)中,我试图从中获取所有输入值我的HTML并更新另一个名为 stocuri 的表中的行:





祝你有美好的一天


This is the code where I get my input names and values from a table called optionale and doing something with these:

<form role="form" autocomplete="off" action="includes/functions/fisa-init.php" method="POST">
<?php
   connectDB();
   $query = mysqli_query($mysqli, "SELECT * FROM `optionale`") or die(mysqli_error($mysqli));
   while($row = mysqli_fetch_array($query))
   { 
?>
   <span><?php echo $row['denumire']; ?></span>
   <input type="text" name="nrBucati">
   <input type="hidden" value="<?php echo $row['cod']; ?>" name="codProdus">
<?php } ?>
</form>

The optionale table looks like this:

The HTML looks like this:

As you can see in the last picture, I have in HTML, a name for input (taken from optionale table) and the actual input in which I write a value.

fisa-init.php:

$stmt3 = $mysqli->prepare("
            UPDATE 
            `stocuri` 
            SET 
            `cantitate` = `cantitate` - ?
            WHERE `cod` = ?
            ");


    $stmt3->bind_param("is", $bucata, $cod);

    // set parameters and execute
    $bucata = mysqli_real_escape_string($mysqli, $_POST['nrBucati']);
    $cod = mysqli_real_escape_string($mysqli, $_POST['codProdus']);

    if (!$stmt3->execute()) 
        {
            echo "Execuția a întâmpinat o eroare: (" . $stmt3->errno . ") " . $stmt3->error;
        }
    $stmt3->close();

    $mysqli->close();

In the code above (fisa-init.php) I am trying to take all the input values from my HTML and update rows in another table called stocuri:

As you can see, only the second row from stocuri table was updated, but I wrote values in all 5 inputs. It got only the last input.

How to modify the while loop in order to take all my inputs value?

If something is not clear, I apologize a hundred times. I will explain all the informations that are needed.

P.S. cod in table optionale is the same with cod in table stocuri. In this way, I know where to update values.

解决方案

Each <input> MUST have an individual name or a named array.

So give each an aditional number like name1,name2 or use an named array like name[]

Finally this name="codProdus[]" is your solution.

Read more here HTML input arrays

Have a nice day

这篇关于While循环-其他输入中只有一个输入正在通过POST发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆