我一直在試圖讓一個形式,我可以更新兩個字段一個字段會是admin_welcomebox
和admin_author
,我由ID試圖更新它所以這裏去我的代碼PHP庫MySQLi沒有更新
<div class="col-lg-6">
<div class="panel panel-color panel-inverse">
<div class="panel-heading">
<h3 class="panel-title">Welcome Box Update</h3>
</div>
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "trres";
$password = "sss";
$dbname = "txxxs";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE admin_news SET welcomebox = '{$admin_news}' SET author = {$admin_author} id='{$id}'";
if ($conn->query($sql) === TRUE) {
echo "<h4 class='bg-success'>You have updated admin welcome box.</h4>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
$conn->close();
}
?>
<div class="panel-body">
<form method="post" action="">
<div class="form-group">
<label for="welcomebox">Welcome Box</label>
<textarea type="text" name="welcomebox" id="welcomebox" placeholder="Enter Your Message" class="form-control"></textarea>
</div>
<div class="form-group">
<label for="author">Author Name</label>
<input type="text" name="author" id="author" placeholder="Author Name" class="form-control"/>
</div>
<div class="form-group text-right m-b-0">
<button class="btn btn-primary waves-effect waves-light" type="submit" name="submit" id="submit">
Update Info
</button>
</div>
</form>
</div>
</div>
</div>
當我嘗試更新它只是刷新頁面沒有別的。
。 RTM http://dev.mysql.com/doc/en/update.html和檢查錯誤會引發你一個語法錯誤。 http://php.net/manual/en/mysqli.error.php,你沒有提到你的'$ conn-> error'。 –
'$ id'在您的代碼中未定義,因此錯誤報告會將您的未定義變量id通知給您。 http://php.net/manual/en/function.error-reporting.php並再次檢查錯誤...正如我在其他評論中所述(如果你正在閱讀這些,那是)。正如'$ admin_news'和'$ admin_author',那麼來自哪裏? –