Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:18:16+00:00 2026-06-10T22:18:16+00:00

I have a little php script that goes to mySql database. I want to

  • 0

I have a little php script that goes to mySql database.

I want to look, before i insert a new record in the database, if the number (value1) equals a record in the database. Wich is also in Row1.

So i want to:

  • Look if the phone number that comes in equals to a phone number in the database. If it does, than it must keep the phone number the same value, only update : longitude, latitude & timestamp.
  • If the phone number equals null. Don’t put any of the values in my database. No records at all.
  • If the phone number is not in the database, also do nothing. Repeat it just like the value is null.

Here’s my current PHP code, where i just make new records when there are any new values.

  <?php



$con = mysql_connect('server', 'user_name', 'pass');
if (!$con)
{
die('Could not connect: ' . mysql_error());
 }

mysql_select_db("db_name", $con);

if (isset($_REQUEST['data'])){
$json = $_REQUEST['data']; // recieve json from app
$data = json_Decode($json);

mysql_query("INSERT INTO test (id, longitude, latitude, timestamp) VALUES ('$data-   >id','$data->longitude','$data->latitude','$data->timestamp')"); 

}

mysql_close($con);
?>

If anyone could help me with this, it would be appreciated!

Thanx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:18:17+00:00Added an answer on June 10, 2026 at 10:18 pm

    You didn’t mentioned the phone number field, so I assumed is phone_number:

    $db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    
    if (isset($_REQUEST['data'])){
        $data = json_decode($_REQUEST['data']);
        if($data->phonenumber){
            $stmt = $db->prepare("SELECT `id` FROM `test` where `id`=:phone_number");
            $stmt->execute(array(':phone_number' => $data->phonenumber));
            $row_count = $stmt->rowCount();
    
            if($row_count && ($data->phonenumber != '')){
                $stmt = $db->prepare("UPDATE `test` SET `longitude`=:longitude, `latitude`=:latitude, `timestamp`=:timestamp WHERE `id`=:phone_number");
                $stmt->execute(array(':longitude' => $data->longitude,':latitude' => $data->latitude,':timestamp' => $data->timestamp,':phone_number' => $data->phonenumber));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this little script in PHP that send a simple request to
I have a script that polls a MySQL database (Nagios, specifically) for the date/time
I have a PHP script that imports CSV files and goes through tens of
Ok, so I have this PHP script that runs in a nice little infinite
This is a little tricky so bear with me: I have a PHP script
I'm a little new at PHP, so my script writing is still progressing. I
I have a PHP script that is using get_dns_record to retrieve and display specific
I have a PHP script that will generate a report using PHPExcel from data
I have a php script that only produces logs to the client. When I
So I have this php script that output an html table with data about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.