Forums
This topic is locked
Problem with sql code Duplicate Entry
Posted 22 Nov 2006 05:48:34
1
has voted
22 Nov 2006 05:48:34 Steve Hines posted:
Hello all, quick question. got a problem with php code, well lack of knowledge too....
i got a registration page that feeds to a thanks page that updates a record.
When a duplicate registration takes place the registration.php page returns a blank sql error that says:
Duplicate entry ' ' for key 2
what i need to do is figure out the statement that will direct this type of error to a page i created.
here is the code on the page, i think it is an else statement but i am not sure how to write it. Please help.
When it does work it goes to my "thanks.php" page, if there is a duplicate record i would like it to go to a page i made, say... you-already-registered.php.
HELP, please!
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "register") {
$hash = md5(uniqid("reg_",true).$_POST['user_email']);
$insertSQL = sprintf("INSERT INTO users (user_company, user_name, user_email, user_password,
user_hash) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['user_company'], "text",
GetSQLValueString($_POST['user_name'], "text",
GetSQLValueString($_POST['user_email'], "text",
GetSQLValueString($_POST['user_password'], "text",
GetSQLValueString($hash,"text");
mysql_select_db($database_foxthermal, $foxthermal);
$Result1 = mysql_query($insertSQL, $foxthermal) or die(mysql_error());
sendMail($_POST['user_email'],$hash);
$insertGoTo = "thanks.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Edited by - shines on 22 Nov 2006 05:50:47
Replies
Replied 22 Nov 2006 09:42:19
22 Nov 2006 09:42:19 ASif Iqbal replied:
i think you need to change to this particular line :-
$Result1 = mysql_query($insertSQL, $foxthermal) or die(mysql_error());
change above this to-
if(@mysql_query($insertSQL, $foxthermal))
{
//thank you
}
else
{
//error
}
$Result1 = mysql_query($insertSQL, $foxthermal) or die(mysql_error());
change above this to-
if(@mysql_query($insertSQL, $foxthermal))
{
//thank you
}
else
{
//error
}