0

I'm having trouble putting values ​​on my php and sending them to My sql.

    <?php
$tempSerialNumber = $_GET['sn'];
$tempLatitude = $_GET['l1'];
$tempLongitude = $_GET['l2'];
$servername = "localhost";
$username = "bornitex_uptoyou";
$password = "12345678";
$dbname = "bornitex_TMS";
$conn = new mysqli($servername, $username,$password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$val1 = $_GET['tempSerialNumber'];
$val2 = $_GET['tempLatitude'];
$val3 = $_GET['tempLongitude'];
$sql = "INSERT INTO LogGPS (SerialNumber, Latitude, Longitude)
VALUES ($val1,$val2,$val3)";
if ($conn->query($sql) === TRUE) {
    echo "save OK";
} else {
    echo "Error:" . $sql . "<br>" . $conn->error;
}
$conn->close();
?>

The value I sent

http://uptoyoutest.bornitexpert.com/add02.php?sn=abc&l1=1.0&l2=2.0

error I got

Error:INSERT INTO LogGPS (SerialNumber, Latitude, Longitude) VALUES (,,)
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 ',)' at line 2

The database I created enter image description here

  • Why not use the original variables you created from `$_GET['sn']` etc? – mario Mar 28 '21 at 08:26
  • I just wrote PHP for the first time, can you help me? – UpFeR Pattamin Mar 28 '21 at 08:51
  • Sure. These are the steps to resolve: ➀ You see the `VALUES (,,)` in your error message. That indicates there's something amiss. ➁ So you look for where that string originates. ➂ Then take a look at your `$sql =` line. ➃ Notice that it references `$val1…3`. ➄ And think about why those are empty. // The linked reference questions might be helpful in this situation. – mario Mar 28 '21 at 09:21
  • Thanks for the advice, I try to read and follow, I can fix it. Thank you very much. <3 – UpFeR Pattamin Mar 28 '21 at 09:27

0 Answers0