...

View Full Version : Error Reporting



MatesOnline
09-24-2004, 04:50 PM
Hi guys.

ok on my page i have a form which on submission inserts an entry to the db

however .. if the username exists it displays a blank page and says ' Duplicate entry for demo'

how would i get that to display that error on register.php as part of teh $message string ?

im a bit confuzzled lol

thanks in advance

Nightfire
09-24-2004, 04:54 PM
Without seeing how your script works, can't really give you any help. If you do all your form valdidation on the same page, you'll be able to echo out the errors then instead of redirecting

marek_mar
09-24-2004, 04:59 PM
You could do it the plain way by just including whatever code needed and ending the script after the include (die()). Without code there nothing more we can say.

MatesOnline
09-24-2004, 05:03 PM
<?php
$currentPage = $_SERVER["PHP_SELF"];

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "register")) {
$insertSQL = sprintf("INSERT INTO members (memid, username, password, realname, age, premium, joined, location, sex, country, starsign, sexuality, profession, marital_status, hair, eyes, height, body_type, race, lookingfor, seeking, likes, dislikes, emailaddress, pwdreminder, status, ppic, timeonline, views) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['memid'], "int"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['realname'], "text"),
GetSQLValueString($_POST['age'], "text"),
GetSQLValueString($_POST['premium'], "text"),
GetSQLValueString($_POST['joined'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['starsign'], "text"),
GetSQLValueString($_POST['sexuality'], "text"),
GetSQLValueString($_POST['profession'], "text"),
GetSQLValueString($_POST['marital_status'], "text"),
GetSQLValueString($_POST['hair'], "text"),
GetSQLValueString($_POST['eyes'], "text"),
GetSQLValueString($_POST['height'], "text"),
GetSQLValueString($_POST['body_type'], "text"),
GetSQLValueString($_POST['race'], "text"),
GetSQLValueString($_POST['lookingfor'], "text"),
GetSQLValueString($_POST['seeking'], "text"),
GetSQLValueString($_POST['likes'], "text"),
GetSQLValueString($_POST['dislikes'], "text"),
GetSQLValueString($_POST['emailaddress'], "text"),
GetSQLValueString($_POST['pwdreminder'], "text"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_POST['ppic'], "text"),
GetSQLValueString($_POST['timeonline'], "text"),
GetSQLValueString($_POST['views'], "int"));

mysql_select_db($database_OnlineFlirting, $OnlineFlirting);
$Result1 = mysql_query($insertSQL, $OnlineFlirting) or die(mysql_error());

$insertGoTo = "index.php?message='Registration Successful, Check your email for your password'";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
}
?>

not sure what code you wanted

MatesOnline
09-24-2004, 05:08 PM
hi guys

just added $message = mysql_error();

then echo'd it on the page where i want it to appear.

thanks for your help & sorry for askin stupid questions :rolleyes:

one moe thing though ... how do i change teh text that is displayed ?

instead of Duplicate entry 'demo' for key 2

i would liek User exists

any ideas ?

thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum