I am getting an error message when I try to insert values in a sql table via php coding. Even I also create a new database again but it's not working. So I need your help to solve it. My error message is given below:
Insertion failed! 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'Usage,Validity,Price)values('indranil','som','WWBIPL_NE_4GB','512kbps','4GB','3' at line 1
My html code is given below :
<html>
<head>
<body>
<form action="insert.php" method="post">
<select name="package">
<option value="WWBIPL_NE_4GB">WWBIPL_NE_4GB</option>
<option value="WWBIPL_NE_6GB">WWBIPL_NE_6GB</option>
</select>
Firstname:<input type="text" name="firstname">
Lastname:<input type="text" name="secondname">
Email:<input type="text" name="email">
Address:<input type="text" name="address">
<input type="submit">
</form>
</body>
</head>
</html>
Here is my PHP code
<?php
$fstname=$_POST["firstname"];
$sndname=$_POST["secondname"];
$price=$_POST["package"];
if($price=="WWBIPL_NE_4GB")
{
$bandwidth="512kbps";
$usage="4GB";
$validity="30days";
$price1="499";
}
else if($price=="WWBIPL_NE_6GB")
{
$bandwidth="512kbps";
$usage="6GB";
$validity="90days";
$price1="1280";
}
$servername="localhost";
$username="root";
$password="";
$dbname="stock";
$conn=mysqli_connect($servername,$username,$password,$dbname);
if(!$conn)
{
die("Connection Failed".mysqli_error($conn));
} $sql="insertintoisuue(Firstname,Lastname,Package,Bandwidth,Usage,Validity,Price)values('$fstname','$sndname','$price','$bandwidth','$usage','$validity','$price1')";
if(mysqli_query($conn,$sql))
{
echo"Data inserted successfully";
}
else
{
echo"Insertion failed".mysqli_error($conn);
}
mysqli_close($conn);
?>
insertintoisuuewould work better written this way:insert into isuue. Apart from that, your SQL is wide open to injections.