I have looked around and found some related articles but i can't seem to get to the bottom of what exactly I am doing wrong here.
I am trying to insert iterator, session username, latitude, longitude and address into coord table. I can't get the lat, long & address to work.
This is the mysql workbench code (works):
INSERT INTO coord(`iterator`,`username`,`lat`,`long`, `address`) VALUES(1,"Slacker1",37.76,-100.42,"213 Street San Diego CA");
This is the php (not working):
$con=mysqli_connect("server","sql_user","pw","db");
$lat=33.26;
$long=-100.33;
$uname=$_SESSION['username'];
$address="265 Road San Diego CA";
mysqli_query($con,"INSERT INTO coord (`iterator`,`username`,`lat`,`long`,`address`) VALUES('$i','$uname','$lat','$long','$address')");
For reference here is the table code:
CREATE TABLE coord (
`iterator` int NULL,
`username` varchar(30) NULL,
`lat` Float(6,3) NULL,
`long` float(6,3) NULL,
`address` varchar(60) NULL
);
Thanks!
Working with the following: Appreciate the help! Staying up too late to work on these things making me forget simple things
$i=1;
$lat=33.26;
$long=-100.33;
$uname=$_SESSION['username'];
$address="265 Road San Diego CA";
mysqli_query($conW,"INSERT INTO coord (`iterator`,`username`,`lat`,`long`,`address`) VALUES('$i','$uname','$lat','$long','$address')");
There appears to be a typo in the query.
mysqli_query($con,"INSERT INTO coord (`iterator`,`username`,`lat`,`long`,`address`) VALUES('$i','$uname','$lat','$long','$address')");
You are passing the variables in your php query as part of the string. Remove the single quotes and append it to the string like this
mysqli_query($con,"INSERT INTO coord (`iterator`,`username`,`lat`,`long`,`address`) VALUES('" . $i . "','" . $uname ."','" . $lat. "','" . $long . "','" . $address . "')");