When updating records, how to add them if not present?
Posted: Fri Mar 25, 2011 1:54 pm
Hi guys!
I have a little script on my site that allows people to save their notes on the page.
The code for saving the notes is the following:
Now if the record of the username is not present, the notes stay blank and you can't save them, as he doesn't update the record.
How to check if the record with the username is present and if not, how to add it instead of updating it? (The adding I can manage, but how to check it first?)
Thanks in advance!
I have a little script on my site that allows people to save their notes on the page.
The code for saving the notes is the following:
Code: Select all
<?php
$notes = $_REQUEST['notes'];
$uname = $user->data['username_clean'];
$con = mysql_connect("***","***","***");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_kitchentube", $con);
mysql_query ("UPDATE notes SET notes = \"$notes\" WHERE username = \"$uname\"");
mysql_close($con);
header( 'Location: index.php' );
?>How to check if the record with the username is present and if not, how to add it instead of updating it? (The adding I can manage, but how to check it first?)
Thanks in advance!