Christiaan Posted October 24, 2011 Share Posted October 24, 2011 Hello everybody. I have a query-question... I have a form that writes data into the database. BUT... I want to verify that data if it allready exists. There are 3 fields that needs to be checked: 1. Type; <- if yes, check 2. 2. Coordinates1 (+ or - 2 from existing record) <- if yes check 3. If no: insert record and echo: "Mine posted succesfully in the database!" 3. Coordinates2 (+ or - 2 from existing record) <- if yes echo: "There is allready a mine of this type in the database on that location!". If no: insert record and echo: "Mine posted succesfully in the database!" (One coordinate uses this format: xxxxxx,yyy (Where xxxxxx is coordinates1 and yyy is coordinates2). A comparison for 1 variable I can find, but not for three and also not how to incorporate the + or - 2. Any help is greatly appreciated. Christiaan code I have so far: <? include 'mining_cfg.php'; // html collect variable $type = $_POST['type']; $level = $_POST['level']; $coordinates1 = $_POST['coordinates1']; $coordinates2 = $_POST['coordinates2']; if ($type == ".$type") AND if ($coordinates1 == ".$coordinates1") AND if ($coordinates2 == ".$coordinates2"){ echo "Mine posted succesfully!"; } else { echo "There is allready a mine of this type in the database on that location!"; } // sql insert into database $sql ="INSERT INTO mining(type, level, coordinates1, coordinates2) VALUES ('".$type."', '".$level."', '".$coordinates1."', '".$coordinates2."')"; //uitvoeren van de query : if (!($temp = mysql_query($sql,$connection))) showerror(); header ( "Location: http://swr.infiniteserve.com/swr-site/test/post_mining.php" ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/249723-query-problem/ Share on other sites More sharing options...
Drummin Posted October 24, 2011 Share Posted October 24, 2011 I don't see where you are querying DB to see if values are already there. Quote Link to comment https://forums.phpfreaks.com/topic/249723-query-problem/#findComment-1281818 Share on other sites More sharing options...
Christiaan Posted October 24, 2011 Author Share Posted October 24, 2011 Because I don't get that right. So scrapped it. Hoping to get some clue's here. Quote Link to comment https://forums.phpfreaks.com/topic/249723-query-problem/#findComment-1281826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.