-
-
Save daveh/c5a691136c7e3b81dc8e72b3fc1054b3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Contact</title> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" | |
href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.min.css"> | |
</head> | |
<body> | |
<h1>Contact</h1> | |
<form action="process-form.php" method="post"> | |
<label for="name">Name</label> | |
<input type="text" id="name" name="name"> | |
<label for="message">Message</label> | |
<textarea id="message" name="message"></textarea> | |
<label for="priority">Priority</label> | |
<select id="priority" name="priority"> | |
<option value="1">Low</option> | |
<option value="2" selected>Medium</option> | |
<option value="3">High</option> | |
</select> | |
<fieldset> | |
<legend>Type</legend> | |
<label> | |
<input type="radio" name="type" value="1" checked> | |
Complaint | |
</label> | |
<br> | |
<label> | |
<input type="radio" name="type" value="2"> | |
Suggestion | |
</label> | |
</fieldset> | |
<label> | |
<input type="checkbox" name="terms"> | |
I agree to the terms and conditions | |
</label> | |
<br> | |
<button>Send</button> | |
</form> | |
</body> | |
</html> |
<?php | |
$name = $_POST["name"]; | |
$message = $_POST["message"]; | |
$priority = filter_input(INPUT_POST, "priority", FILTER_VALIDATE_INT); | |
$type = filter_input(INPUT_POST, "type", FILTER_VALIDATE_INT); | |
$terms = filter_input(INPUT_POST, "terms", FILTER_VALIDATE_BOOL); | |
if ( ! $terms) { | |
die("Terms must be accepted"); | |
} | |
$host = "localhost"; | |
$dbname = "message_db"; | |
$username = "root"; | |
$password = ""; | |
$conn = mysqli_connect(hostname: $host, | |
username: $username, | |
password: $password, | |
database: $dbname); | |
if (mysqli_connect_errno()) { | |
die("Connection error: " . mysqli_connect_error()); | |
} | |
$sql = "INSERT INTO message (name, body, priority, type) | |
VALUES (?, ?, ?, ?)"; | |
$stmt = mysqli_stmt_init($conn); | |
if ( ! mysqli_stmt_prepare($stmt, $sql)) { | |
die(mysqli_error($conn)); | |
} | |
mysqli_stmt_bind_param($stmt, "ssii", | |
$name, | |
$message, | |
$priority, | |
$type); | |
mysqli_stmt_execute($stmt); | |
echo "Record saved."; |
@LOL-monkey The error message refers to a variable $conn not existing on line 30, but there is no such variable on line 30 of your code - could there be multiple versions of your script perhaps or it wasn't saved when you tried to run it?
i have already save it when i run it
Hey Dave,
Is there any way I can have the database table on another HTML page?
if there are any YouTube videos related to this, could you provide the links?
can u tell me what wrong pls
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 2 in C:\xampp\htdocs\THE-BEST\aaa.php:31 Stack trace: #0 C:\xampp\htdocs\THE-BEST\aaa.php(31): mysqli_stmt_prepare(Object(mysqli_stmt), 'INSERT INTO inf...') #1 {main} thrown in C:\xampp\htdocs\THE-BEST\aaa.php on line 31
@zoro7sn There's an extra comma in your SQL after the values list - it should be VALUES (?, ?, ?, ?)
but it did not get fix
![屏幕截图 2024-04-28 003047](https://private-user-images.githubusercontent.com/113596477/326192172-369fc869-7d16-46f1-a329-0d82400a40b6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxNTg3MTYsIm5iZiI6MTcyMjE1ODQxNiwicGF0aCI6Ii8xMTM1OTY0NzcvMzI2MTkyMTcyLTM2OWZjODY5LTdkMTYtNDZmMS1hMzI5LTBkODI0MDBhNDBiNi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzI4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyOFQwOTIwMTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xMTJhMzhhZT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