The code below is giving an error.The query alone is working fine on phpmyadmin directly but but in my php code:
Database Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'to\',\' message\',\'from\')' at line.. but i cannot figure out why?
<?php
$con = mysqli_connect("localhost","","","");
if (!$con)
{
echo" Not connected to database";
die('Could not connect: ' . mysqli_error());
}
if(isset($_POST['submit'])){
$username=$_SESSION["username"];
$sql = "INSERT INTO `dbase.mail`(`Date`, `to`, `message`, `from`) VALUES (CURDATE(),\'$_POST[username1]\',\'$_POST[message]\',\'$username\')";
$xy=mysqli_query($con,$sql);
if (!$xy)
{
die('Database Error ' . mysqli_error($con));
}
echo "Your message is stored";
}