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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:34:47+00:00 2026-05-28T00:34:47+00:00

Scenario: I have got a client, php script and a MySQL database. I am

  • 0

Scenario:

I have got a client, php script and a MySQL database. I am sending information from the client to the database which the values include the name and favorite color. I have got 2 rows in MySQL database.

Name | Favorite Color

Johnny | Green

Where Name is a primary key.

Every time, the client would be sending both his name and favorite color. So if name (primary key) exist, it shows error. How should I set my php script to react if the client wants to update his favorite color? In other words, keep primary key but update favorite color.

script.php

<?php
mysql_connect("localhost","root","")
mysql_select_db("Information");

$name = mysql_real_escape_string($_POST["name"]);
$color = mysql_real_escape_string($_POST["color"]); 

$sql=mysql_query("insert into Male (name, color) VALUES ('$name','$color')"); 

mysql_close();
  • 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-28T00:34:47+00:00Added an answer on May 28, 2026 at 12:34 am
    $sql=mysql_query("INSERT INTO Male (name, color) VALUES ('".$name."', '".$color."')
    ON DUPLICATE KEY UPDATE color='".$color."'");
    

    http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html

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

Sidebar

Related Questions

The scenario is I have got 2 dropdown list and a table in which
I am having a scenario where there are several subclasses which have got similar
We've got the following scenario: Central Database (replicated across multiple servers) Client Database 1
We've got into a very tricky scenario in a project. We have used lot
Scenario I have recently graduated from university with a degree in Computer Science. My
Here's the scenario: I've got a regular hyperlink on my .ascx. (no I have
In my scenario I have a lot of buttons or other controls which I
I'm working on an application which accesses data from an Oracle 11g database. I'm
I have got the following scenario. In my SL application, I am getting some
Scenario: Think you have got 90TB of text in 200 tables. This is structured

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.