I have a database with 4 columns Date
,to
,message
,from
one of date
format and all varchar
. Following is the error that i am getting:
Error: Database Error Unknown column 'anything i enter into the form's first field' in 'field list'. Here is my code:
form:
<form method='post' name:mail>
<label>
<p>
Send to Username:<p>
</label>
<input type="text" name="user" hint="Enter username" id="user" placeholder = "Name" >
</label><p>
Message:
<p>
<label>
<textarea name="message" cols="40" rows="5">
</textarea><br>
<input type="submit" name="submit" id="submit" value="Send" />
I know i should not have used $POST_[] directly into the query but i am just testing it.
php code:
<?php
$con = mysqli_connect("localhost","","","");
if (!$con)
{
echo" Not connected to database";
die('Could not connect: ' . mysqli_error());
}
if(isset($_POST['submit']))
{
$username1=$_SESSION["username"];
$sql = "INSERT INTO anengine_dbase.mail(`Date`,`to`,`message`,`from`) VALUES (CURDATE(),`$_POST[user]`, `$_POST[message]`,`$username1`)";
$xy=mysqli_query($con,$sql);
if (!$xy)
{
die('Database Error ' . mysqli_error($con));
}
echo "message successfully recorded ";
}
?>