简体   繁体   English

POST 数据 PHP-MySql 到 HTML POST 到 PHP-MySql

[英]POST Data PHP-MySql to HTML POST to PHP-MySql

I'm nubie and stuck in this POST to POST please help:我是 nubie 并且卡在这个 POST 到 POST 请帮助:

    <table celpadding=3 cellspacing=2 border=1 width=83%>
    <tr>
    <th>No.</th>
    <th>ID Number</th>
    <th>Name</th>
    <th>TOTAL</th>
    <th>AVERAGE</th>
    <th>Input</th>
    </tr>";
    $xa=0;
    while ($show= mysql_fetch_array($qry))
        {
    $idnmbr = $show['idnbr'];
    $name = $show['name'];
    $tot = $show['jml'];
    $avg = round($show['avg'],0);
    $xa++;

    $display_block .= "
    <form method=POST action=inputact.php>
    <tr>
    <td>$xa</td>
    <td>$idnmbr<input type=hidden name=nmbr_id value=$idnmbr><br></td>
    <td>$name<input type=hidden name=nm value=$name><br></td>
    <td align=center>$tot<br></td>
    <td align=center>$avg<br></td>
    <td align=center><input type=value size=3 name=input value='' </td>
    </tr>";
    }

    $display_block .= "</table>
    <br>
    <input type=submit name=submit size=15 value=SAVE>
    <br>
    </form>";
    print $display_block;
    ?>

the question is in how the inputact.php wil be?问题在于 inputact.php 将如何? I've see another question similar with this but I stil don't get it, how to send $idnmbr Value, $name Value, and Input Value to MySQL TABLE in inputact.php我看到另一个与此类似的问题,但我仍然不明白,如何在 inputact.php 中将 $idnmbr 值、$name 值和输入值发送到 MySQL TABLE

I'm try using foreach but stil wrong, please help我正在尝试使用 foreach 但还是错误,请帮忙

inputact.php:输入法.php:

    <?php
    //db connect
    $conn = mysql_connect("localhost","root","") or die (mysql_error());
    mysql_select_db("rumble",$conn) or die (mysql_error());

    //$addfc = "insert into perkiraan values ('$_POST[prdk_id]','$_POST[prdk_nm]','$_POST[input]', now())";
    //mysql_query($addfc);

    foreach ($_POST['prdk_id'] as $i)
    {
    INSERT INTO gambuz VALUE ('$_POST[nmbr_id]', '$_POST[nm]', '$_POST[input]')";
    mysql_query($addfc);
    }
    ?>

Your code is badly written.你的代码写得不好。 Please get some good books on PHP I will suggest you start with w3school, Beginning PHP by Matt Doyle, and Head First PHP and MYSQL.请获取一些关于 PHP 的好书,我建议您从 w3school、Matt Doyle 的 Beginning PHP 和 Head First PHP 和 MYSQL 开始。

Back to the problem pls, elaborate appropriately to help fix your problem.回到问题,请适当详细说明以帮助解决您的问题。

or better still try this或者最好还是试试这个

<?php 

$conn = mysqli_connect("localhost", "username", "passsword");

if(!conn) {

 die("<h2>Unable to establish connection with the provided parameters</h2>" . mysqli_error($conn)); 

}

//All your post gloabl variable comes in here 

$nmbr_id = $_POST['nmbr_id'];
$nm = $_POST['nm'];
$input = $_POST['input']; 


$query = "INSERT INTO `gambuz` VALUE (`$nmbr_id`, `$nm`, `$input`)"; 

$result = mysqli_query($conn, $query);


//since this is a post superglobal, there is no need to use the foreach loop, just move on;

if($result) {
    echo "<h2>Record inserted succesfully"; 
} else {

    echo "Failed to inser record" . mysqli_error($conn); 
}

If this does not solve your problem, pls reply my answers.如果这不能解决您的问题,请回复我的答案。 Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM