-
-
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."; |
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 (?, ?, ?, ?)
Here is my php code. I get the following error when I hit submit.
Parse error: syntax error, unexpected identifier "sisis" in C;\xampp\htdocs\SAR\process-timesheet.php on line 32
1 <?Php
2
3 $member = $_POST["member"];
4 $date = $_POST["date"];
5 $type = $_POST["type"];
6 $hours = $_POST["hours"];
7 $note = $_POST["note"];
8
9 $host = "localhost";
10 $dbname = "lcsar_db";
11 $username = "root";
12 $password = "";
13
14 $conn = mysqli_connect(hostname:$host,
15 username: $username,
16 password: $password,
17 database: $dbname);
18
19 if (mysqli_connect_errno()) {
20 die("Connection error: " . mysqli_connect_error());
21 }
22
23 $sql = "INSERT INTO timesheet (member, date, type, hours, note);
24 VALUES (?, ?, ?, ?, ?);
25
26 $stmt = mysqli_stmt_init($conn);
27
28 if ( ! mysqli_stmt_prepare($stmt, $sql)) {
29 die(mysqli_error($conn));
30 }
31
32 mysqli_stmt_bind_param($stmt, "sisis", $member, $date, $type, $hours, $note);
33
34 mysqli_stmt_execute($stmt);
35
36 echo "Record saved";
@paulagliano I can't see anything wrong with your code - the error says it's on line 32, perhaps with the second argument to the function there - try using single quotes around the "sisis" string to see if that makes a difference: 'sisis'
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?