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 8766483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:33:53+00:00 2026-06-13T16:33:53+00:00

I’ve been trying to accomplish this, but as other issues I just can’t figured

  • 0

I’ve been trying to accomplish this, but as other issues I just can’t figured it out. I’ve been reading around for posibles solutions but non of them goes along with my code, or if they do I can’t figure out how or where to use them.

I have a DB where a user sends records. The database consist in few tables containing the Following "Name, Lastname, Phone". If any of this values is duplicate, I would like my code to identify and Ignore the submission of the Form if ALL this VALUES already exist on the DB.

Here is my code:

        <?php

        $con = mysql_connect("HOST","USER","PASS");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db("testdb", $con);
        $sql="INSERT INTO people (Name, LastName, Phone)
        VALUES
        ('$_POST[Name]','$_POST[LastName]','$_POST[Phone]')";

        if (!mysql_query($sql,$con))
          {
          die('Error: ' . mysql_error());
          }
        
        echo "Record Added";

        mysql_close($con);
        ?>
  • 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-13T16:33:54+00:00Added an answer on June 13, 2026 at 4:33 pm

    The mysql_* function are all deprecated now, and should NEVER be used. change your code to do something like the following:

    //Set up a PDO connection to MySQL
    $host = 'host_name';
    $dbname = 'database_name';
    $user = 'user_name';
    $pass = 'user_pass';
    try
    {
        $DB = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); 
    }
    catch(PDOException $e)
    {  
        echo $e->getMessage();  
    }
    
    //Determine whether the appropriate values have been passed.
    if(isset($_POST['Name']))
    {
        $name = $_POST['Name'];
    }
    else
    {
        echo "You must provide a name!";
            exit; //This may not be what you want to do here, it's an example action
    }
    
    if(isset($_POST['LastName']))
    {
            $name = $_POST['LastName'];
    }
    else
    {
        echo "You must provide a last name!";
            exit; //This may not be what you want to do here, it's an example action
    }
    
    if(isset($_POST['Phone']))
    {
            $name = $_POST['Phone'];
    }
    else
    {
        echo "You must provide a phone number!";
            exit; //This may not be what you want to do here, it's an example action
    }
    
    
    //Set up the query using anonymous values
    $sql="INSERT INTO people (Name, LastName, Phone) VALUES ('?','?','?')";
    $sth = $DB->prepare($sql);
    
    try
    {
            //Attempt to execute the insert statement
            $sth->execute(array($_POST[Name], $_POST[LastName], $_POST[Phone]));
            echo "Record Added";
    
    }
    catch(PDOException $e)
    {
            //If the insert failed, then you can handle the error, and determine
            //what further steps need to be taken.
            echo "Record Not Added";
    }
    

    Here’s another question with a similar setting, that may also be useful to you:

    https://stackoverflow.com/a/10414922/1507210

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there's a lot of other questions out there that deal with this
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.