I am trying to edit a SQL database from a Cordova app. I have this PHP code:
<?php
$servername = "localhost";
$username = "user1";
$password = "example";
$dbname="users";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$name = "'".$_POST["name"]."'";
$pass = "'".$_POST["password"]."'";
$email = "'".$_POST["email"]."'";
$x = $conn->query("INSERT INTO USERS(Name, Password, email) VALUES ($name, $pass, $email)");
if($x)
echo "OK";
else echo "No";
echo $name;
echo '<br>';
echo $pass;
echo '<br>';
echo $email;
?>
Every time I want to do this action, the PHP prints on the screen the following message:
Connected successfully
No
'abcd'
'abcd'
'abc@email'
The message from above is printed because of the echo functions I wrote. I see that the $name, $pass and $email variables are received from my form, the connection is done successfully, but the "No" message means the data was not introduced in the database.