I am very new to php and I am trying to insert data into my database. I already have atable called "Locate" in my database that I am trying to update, it has the columns "Longitude", "Latitude" and "ID".
Firstly is my code below suitable to update this table.
Secondly, I want to add code that will check the database and make sure the ID is not one that has already been used, thanks in advance.
<?php
$longitude = $_GET['longitude'];
$latitude = $_GET['latitude'];
$username = $_GET['username'];
// Create connection
$con=mysqli_connect("localhost","dbuser","password","yviewdb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "UPDATE CFP SET Longitude = '$longitude' AND Latitude = '$latitude' WHERE ID = '$username';";
$res = mysql_query($sql,$con) or die(mysql_error());
// Close connections
mysqli_close($con);
if ($res) {
echo "success";
}else{
echo "failed";
}
?>