我有问题。 我试图制作CMS,但我无法通过php更新我的数据。 它们是变量而且它不接受我的查询,但是当我使用静态值时它会更新。 这是我的代码。 我遇到的错误是$ menu1未定义
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="author" content="Robert Michalski">
</head>
<body>
<h1>CSS</h1>
<h2>+HTML 5</h2>
<form action="index.php" method="post">
Edycja menu
<input type="text" name="menu1" placeholder="menu1">
<input type="text" name="menu2" placeholder="menu2">
<input type="text" name="menu3" placeholder="menu3">
<input type="text" name="menu4" placeholder="menu4">
<input type="submit" name="button" value="save">
</form>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "wia27";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE menu SET menu1='$menu1' WHERE id=1";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
<section>
<article>
<h3>box</h3>
<p>Lorem ipsum</p>
</article>
<div class="ads">
<div class="little_ad">
Box1
</div>
</div>
</section>
<footer>
Robert Michalski 2016 ©
</footer>
</body>