0

hi i have this error in my page. try to write to SQL.

Error: INSERT INTO test123(username,password,group)VALUES('', '' , '') 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 'group)VALUES('', '' , '')' at line 1

this is my code.

<html>
<div style="margin:10px auto; width:500px;">
<form method="post" action="">
<label>Name</label><br>
<input type="text" name="username"><br>
<label>Password</label><br>
<input type="text" name="password"><br>
<label>Group</label><br>
<input type="text" name="group"><br>
<input type="submit" name="submit">


</form>
</div>

</html> 


<?php
$servername = "localhost";
$username = "root";
$password = "pass";
$dbname = "local";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$Name = $_POST['username'];
$Password = $_POST['password'];
$Group = $_POST['group'];

$sql = "INSERT INTO test123(username,password,group)VALUES('$Name', '$Password' , '$Group')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
OmerAD
  • 13
  • 4
  • not sure if it makes any sense, but maybe add some spaces : `... group) VALUES ('$Name' ...` – ikos23 Mar 31 '18 at 05:37
  • Try adding @$_POST[] to all post data to cater for isset conditions and concatenate variables in values method like VALUES('".$name.'") – Moses Mar 31 '18 at 05:40
  • You are using a reserved mysql keyword group. Rename that field in your db, or if you want to use it anyway, then enclose it in backticks in your SQL string. – Karlo Kokkak Mar 31 '18 at 05:42

0 Answers0