Jump to content

Query problem!


Christiaan

Recommended Posts

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" ); 

?>

Link to comment
https://forums.phpfreaks.com/topic/249723-query-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.