0

( ! ) Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\mystore\customer.php on line 33

<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "goodoneboy";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
<?php
$servername = "localhost";
$username = "root";
$password = "goodoneboy";
$dbname = "my store";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo $_POST["name"];
echo $_POST["address"];
echo $_POST["amount_paid"];
$sql = "INSERT INTO customer (Name,Address,Amount_paid)
VALUES ('$_POST["name"]','$_POST["address"]',' $_POST["amount_paid"]')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
</body>
</html>
ZygD
  • 22,092
  • 39
  • 79
  • 102
Akshit Verma
  • 77
  • 2
  • 8
  • Note also that your code is **extremely unsafe**. You should never put `POST` values (or any variable values) directly into queries, use prepared statements instead. – tim Apr 19 '15 at 09:24

1 Answers1

3

i would put your post values in a variable and then use them in your sql statement or concatenate the string to avoid the use of so many quotations.

"INSERT INTO customer (Name,Address,Amount_paid) VALUES (" . $_POST["name"] . "," .$_POST["address"]. "," . $_POST["amount_paid"] . ")";

Try that instead. Or

"INSERT INTO customer (Name,Address,Amount_paid) VALUES ( '$name', '$address','$amount_paid')";
andrew hutchings
  • 343
  • 1
  • 5
  • 18