简体   繁体   中英

POST Data PHP-MySql to HTML POST to PHP-MySql

I'm nubie and stuck in this POST to POST please help:

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

I'm try using foreach but stil wrong, please help

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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