adrianTNT Posted September 1, 2006 Share Posted September 1, 2006 Hello.I made a membership signup form. (I dont have many PHP+MySQL skills, this was made in Dreamweaver).The user completes a form to signup (signup.php).If the new user is successfully created then is sent to message.php telling him that the new username was created. BUTIf the username entered is already in database then the singup.php page replaces all site layout content and posts the error [b]"Duplicate entry 'Adrian' for key 2".[/b]How can I handle these errors so that if the username is already taken then the visitor is sent to [b]message.php?message=Username Taken[/b]Rather than showing the ugly SQL error on page.Thank you.- Adrian.I dont know if this helps, the code I have now on signup.php:[code]if (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO affiliates (aff_full_name, aff_user_name, aff_email, aff_pass) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['full_name_box'], "text"), GetSQLValueString($_POST['username_box'], "text"), GetSQLValueString($_POST['email_box'], "text"), GetSQLValueString($_POST['pass_box'], "text")); mysql_select_db($database_affiliates, $affiliates); $Result1 = mysql_query($insertSQL, $affiliates) or die(mysql_error()); $insertGoTo = "message.php?message=New username created successfully.&type=info"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted September 1, 2006 Share Posted September 1, 2006 Well, you have a die() statement -- just write a custom handler. Quote Link to comment Share on other sites More sharing options...
adrianTNT Posted September 1, 2006 Author Share Posted September 1, 2006 [quote author=fenway link=topic=106526.msg426084#msg426084 date=1157132604]Well, you have a die() statement -- just write a custom handler.[/quote]Thanks Fenway, so I guess I have to replace die(mysql_error());with myfunction(); ?!Another question in this case...What php code do I need in order to open an URL?So that I replace the "die" block with something like:[b]Open url : message.php?message=Error, user already exists.[/b]How can I open the URL by php code?Thank you. Quote Link to comment Share on other sites More sharing options...
adrianTNT Posted September 1, 2006 Author Share Posted September 1, 2006 I found how to open an url by php:[code]<?php header("Location: http://asite.com/file.html");?>[/code]I think I found my answers for now.Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.