MYSQL / PHP- echo从数据库中插入数据

时间:2016-03-23 05:30:57

标签: php mysql forms insert-into

我对此很新,所以任何帮助都会受到赞赏。 我已成功将数据插入数据库。但是,如何将插入数据库的数据回显到表单字段中。我试过了public Profile getProfile(long id) { SQLiteDatabase db = this.getReadableDatabase(); try { String selectQuery = "SELECT * FROM " + TABLE_PROFILES + " WHERE " + KEY_PROFILES_ID + " = " + id; Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list Profile profile = new Profile(); if (cursor.moveToFirst()) { doWhatEver(); } cursor.close(); finally { db.close(); } return profile; } 。它确实可以工作

  

注意:未定义的变量:c_fname in    /Applications/MAMP/htdocs/PhpProject2/customer/Cus_Account.php 的   在线 129

PHP

value="<?php echo [variable here]; ?>"

HTML

<?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>";
}
?>

任何建议都会非常感激。

1 个答案:

答案 0 :(得分:2)

我认为您尝试做的是在提交数据后将值保留在表单中。

所以,如果我是对的,请执行此操作

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