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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.