MYSQL/PHP- 从数据库中回显插入的数据

MYSQL/PHP- echo inserted data out of database

我对此很陌生,如有任何帮助,我们将不胜感激。 我已成功将数据插入数据库。但是我怎样才能将插入数据库的数据回显到表单字段中。我试过 value="<?php echo [variable here]; ?>"。它确实有效,我得到的只是

Notice: Undefined variable: c_fname in /Applications/MAMP/htdocs/PhpProject2/customer/Cus_Account.php on line 129

PHP

<?php
if (isset($_POST['Update'])) {
$c_fname = $_POST['fname'];
$c_lname = $_POST['lname'];
$c_email = $_POST['email'];
$c_phone = $_POST['phone'];



$insert_det = "INSERT INTO Cus_acc_details(CUS_Fname,CUS_Lname,Cus_Email,CUS_Phone) VALUES (?,?,?,?)";
$stmt = mysqli_prepare($dbc, $insert_det);
//new
// $stmt = mysqli_prepare($dbc, $insert_c);
//debugging
//$stmt = mysqli_prepare($dbc, $insert_c)  or die(mysqli_error($dbc));

mysqli_stmt_bind_param($stmt, 'sssi', $c_fname, $c_lname, $c_email, $c_phone);

/* execute query */
$r = mysqli_stmt_execute($stmt);

if ($insert_det) {
    echo "<script> alert('registration sucessful')</script>";
 }
 } else {
echo "<b>Oops! Your passwords do not </b>";
}
?>

HTML

    <section class="container">
    <form id="myform " class="Form" method="post" action="Cus_Account.php?c_id=<?php echo $c_id ?>" accept-charset="utf-8">

        <!--                    <div id="first">-->
        <input type="text" id="fname" name="fname" value="<?php echo $c_fname;   ?>" required> 
        <input type="text" id="lname" name="lname"  required>
        <input type="text" id="email" name="email" value="<?php echo    $_SESSION['Cus_Email']; ?>" required>
        <input type="number" id="phone" name="phone"  required>
        <input type="submit" name="Update" value="Update">
        <br>
    </form>

如有任何建议,我们将不胜感激。

我认为您要做的是在提交数据后保持表单中的值。

所以如果我是对的,就这样做

<section class="container">
<form id="myform " class="Form" method="post" action="Cus_Account.php?c_id=<?php echo isset($c_id) ? $c_id : ''; ?>" accept-charset="utf-8">

    <!--                    <div id="first">-->
    <input type="text" id="fname" name="fname" value="<?php echo isset($_POST['fname']) ? $_POST['fname'] : '';   ?>" required> 
    <input type="text" id="lname" name="lname"  required>
    <input type="text" id="email" name="email" value="<?php echo isset($_SESSION['Cus_Email']) ? $_SESSION['Cus_Email'] : ''; ?>" required>
    <input type="number" id="phone" name="phone"  required>
    <input type="submit" name="Update" value="Update">
    <br>
</form>