I want to check if the value $id already exist in the column id.
If it does i want to call a query, else i want to do another query.
Seems quite easy, but not for me.
Here’s the important code
if (isset($_GET['data'])) {
$data = json_decode($_GET['data'], true);
$id = $data['id'];
$latitude = $data['latitude'];
$longitude = $data['longitude'];
$timestamp = $data['timestamp'];
$result = mysql_query("SELECT * FROM locatie WHERE id='$id'");
if("id='$id'")
{
$query = "Update locatie
SET longitude = '$longitude',
latitude = '$latitude',
timestamp = '$timestamp'
WHERE id = '$id'";}
else
//Als het nummer bekend is
{
//Als het een nieuw nummer is
$query = sprintf("INSERT INTO locatie (id, longitude, latitude, timestamp) VALUES ('%s', '%s', '%s', '%s') ", mysql_real_escape_string($id) , mysql_real_escape_string($longitude), mysql_real_escape_string($latitude), mysql_real_escape_string($timestamp));}
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "OK";
// Free resultset
mysql_free_result($result);
}
But now the code wont do anything, i know both of the queries work fine seperatelym but not when i SELECT From locatie….
Any help would be appreciated
mysql_num_rows() Get number of rows in result
https://www.php.net/manual/en/function.mysql-num-rows.php