Reputation: 465
I'm pretty new to this, so any help would be appreciated.
I have successfully inserted data into a database. But how can i echo the data inserted into the database out into a form field. I have tried the value="<?php echo [variable here]; ?>"
. it does work all i get is
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>
any suggestions would be much appreciated.
Upvotes: 0
Views: 206
Reputation: 1792
I think what you're trying to do is to keep the values in form once you submitted the data.
So If I'm right, Do this
<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>
Upvotes: 2