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();
http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html