|
Posted by linda on 10/16/06 21:04
I very new to php could someone please explain how to write an error message
into my AddNew.php below. id is set to unique so at the moment if someone
adds a product and the id is already in the database, it just doesn't enter
anything. Ideally I would like to display an error message, with a back
button to correct the id.
So far I've tried running a SELECT query with an if statement prior to the
INSERT but I just don't know enough php to get this to work. I would be
very greatful for any info and advice from those in this newsgroup.
Many, many thanks in advance,
Linda
[php]
<?php
//login details
@mysql_connect($host,$user,$password) or die("Unable to connect with
server!");
@mysql_select_db($database)or die("Unable to connect database, please try
later!");
$id=mysql_real_escape_string($_POST['id']); //This is set to unique
$name=mysql_real_escape_string($_POST['name']);
$info=mysql_real_escape_string($_POST['info']);
$pic=mysql_real_escape_string($_POST['pic']);
$lg_pic=mysql_real_escape_string($_POST['lg_pic']);
$price=mysql_real_escape_string($_POST['price']);
$query = "INSERT INTO floral VALUES
('$id','$name','$info','$pic','$lg_pic','$price')";
mysql_query($query);
header("Location: added.php");
mysql_close();
?>
[Back to original message]
|