I have been trying to add a row in my database but i keep on recieving the same error no matter what I do. The error is Parse error: syntax error, unexpected T_STRING . This is my code:
<!DOCTYPE html>
<html>
<body>
<?php
$con=mysqli_connect("mysql5.000webhost.com","********","******","*******");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Connecting to the Database works
INSERT INTO test (`1`, `2`, `3`, `4`) VALUES (\'11\', \'11\', \'11\', \'11\');
mysqli_close($con);
?>
</body>
</html>
You need to execute a query - mysqli_query()
$query = mysqli_query("INSERT INTO test (`1`, `2`, `3`, `4`) VALUES ('11', '11', '11', '11')");
remove the \
in the statement,
$query = "INSERT INTO test (`1`, `2`, `3`, `4`) VALUES ('11', '11', '11', '11')";
but if the columns are integer,
$query = "INSERT INTO test (`1`, `2`, `3`, `4`) VALUES (11, 11, 11, 11)";
I notice your sql statement is written as if it was php code. SQL is not parsed directly by php interpreter. you need to first put the sql into a variable then execute that statement. also, you are escaping the single quotes, not good
$sql="INSERT INTO test (`1`, `2`, `3`, `4`) VALUES ('11', '11', '11', '11')";
$result = $db->query($sql);
while ($data = $result->fetch_assoc())
{
$retval[]= $data;
}
assuming $db is a valid connection