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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:32:07+00:00 2026-05-29T09:32:07+00:00

I have almost no experience with PHP and right now I’m stuck at the

  • 0

I have almost no experience with PHP and right now I’m stuck at the total beginning, which is really frustrating. I have a code, which seems to work. From my app I can input values and put them in my PHP database. Thing is that he only inputs the very last value from my PHP code. So the app aside: If I only use the PHP code to input something in my database he always only takes the last value. Here is my code:

<?php
$DB_HostName = "localhost";
$DB_Name = "xxx";
$DB_User = "xxx";
$DB_Pass = "xxx";
$DB_Table = "contacts";

if (isset ($_GET["name"]))
    $name = $_GET["name"];
else
    $name = "Blade";

if (isset ($_GET["lastname"]))
    $lastname = $_GET["lastname"];
else
    $lastname = "Xcoder";

if (isset ($_GET["number"]))
    $number = $_GET["number"];
else
    $number = "111";

$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 
mysql_select_db($DB_Name,$con) or die(mysql_error()); 

$sql = "insert into $DB_Table (Firtname) values('$name');";
$sql = "insert into $DB_Table (Lastname) values('$lastname');";
 $sql = "insert into $DB_Table (Number) values('$number');";

$res = mysql_query($sql,$con) or die(mysql_error());

mysql_close($con);
if ($res) {
    echo "success";
}else{
    echo "faild";
}// end else
?>

To clarify: If I only have the firstname value, he inputs it in the right place (firstname). If I have a firstname and lastname value, he only inputs the lastname value, but not the firstname value (still at the right place lastname). And the same for number. If I have a firstname, lastname and a number, he only puts the number in the right place but not the other values. In addition I can only do it once. If I want to enter another contact he always says (Duplicate entry ‘myentry’ for key ‘PRIMARY’).

  • 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-05-29T09:32:07+00:00Added an answer on May 29, 2026 at 9:32 am

    You overwrite your query, 2 ways to solve. Either 3 different variables, or 1 variable with 3 queries in it. I would prefer the 2nd option

    $sql = "insert into $DB_Table (Firtname) values('$name');";
    $sql .= "insert into $DB_Table (Lastname) values('$lastname');";
    $sql .= "insert into $DB_Table (Number) values('$number');";
    
    $res = mysql_query($sql,$con) or die(mysql_error());
    

    Or if it can be 1 row in the table, as it is the same table anyways:

    $sql = "insert into $DB_Table (Firtname,Lastname,Number) values('$name','$lastname','$number');";
    $res = mysql_query($sql,$con) or die(mysql_error());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have limited programming experience, and almost none with PHP. However I've been given
I write server code but have little to almost no JQ experience. I have
I admit that I have almost none experience of unittesting. I did a try
I almost always have a Scala REPL session or two open, which makes it
I have lots of experience of writing php scripts that are run in the
Hey, I have almost no experience with Xilinx. I have a group project for
In my 4 years of experience,I have developed a lot of web applications. Now,
...what does it mean? I have almost no experience with jQuery, and need to
I don't know almost anything about this so if you have some experience let's
I have almost no experience with querying XML data with T-SQL. Given the XML

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.