即時提出如何創建一個表格,將$ _post thingy中的輸入保存到表格中,非常感謝!或者你能幫我修復這個代碼或創建一個新的工作請嗎?我需要你的幫助,請再次感謝!
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "tsukishiro";
$id = $_POST['id'];
$name = $_POST['name'];
$comment = $_POST['comment'];
$input = $_POST['input'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO connection(ID, name, comment, input) VALUES ('null', '$name', '$comment', 'input')";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
}
if (empty($_POST["input"])) {
$input = "";
} else {
$input = test_input($_POST["input"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
echo "<input type='text' name='id'>";<br><br>
echo "<input type='text' name='name'>";
echo "<input type='text' name='comment'>";
echo "<input type='text' name='input'>";
echo "<input type='submit' name='submit'>";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>`
您是否嘗試運行的代碼?確切的問題是什麼?你有沒有收到任何錯誤? – phpPhil 2015-03-03 05:06:21
您錯過了表格標籤 – starkeen 2015-03-03 05:09:40
您使用的是Joomla,那麼爲什麼不堅持Joomla API。請仔細閱讀文檔 – Lodder 2015-03-03 17:30:25