Swathi Swathi -4 years ago 101
MySQL Question

phpmyadmin insert statement syntax

The values aren't getting inserted into the table. I tried both ways,one is directly inserting data,the other one is by passing the saved variable value and yet it isn't getting inserted. Could some one help?

The structure of the table is

CREATE TABLE store
(`storeid` int, `storename` varchar(20), `starttime` int,`stoptime` int, `address` varchar(20), `contact` varchar(20));


<?php include 'database.php'; ?>

<?php
echo "hello";
$id= $_POST['t1'];
$name=$_POST['t2'];
$stime=$_POST['t3'];
$sttime=$_POST['t4'];
$add=$_POST['area'];
$con=$_POST['no'];
echo 'end';

mysqli_query($connect,"INSERT INTO store(t1,t2,t3,t4,area,no) VALUES (' 1 ',' hai ',' 9 ',' 10 ',' asa ',' 29148 ')");


mysqli_query($connect,"INSERT INTO store(t1,t2,t3,t4,area,no) VALUES (' $id ',' $name ',' $stime ',' $sttime ',' $add ',' $con ')");


if(mysqli_affected_rows($connect) > 0){
echo 'no';
echo "<p>Employee Added</p>";

}

Answer Source

You are using the Formular fields as column names. That won't work. you have to use the column names:

mysqli_query($connect,"INSERT INTO store(storeid,storename,starttime,stoptime,address,contact) VALUES VALUES ('$id','$name','$stime','$sttime','$add','$con')");    

And as i wrote in my comment: Use prepared Statements to prevent SQL injection.

Also you should check for Errors after executing SQL Statements (mysqli_error()). If you do it, you see the error message and it is easier to evaluate it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download