hi there, php noob here. i was wondering if someone could help me out of a jam here. i have a script that checks my form if my fields are properly filled or not. while it does indeed check the form, it does not return the errors back to the user so that he/she knows what was wrong. all the script does is it resets the form without telling the user what happened. any ideas? any and all help will be greatly appreciated. the code is below. please tell me what i did wrong. thanks.
<?php
session_start();
require_once('config.php');
$errmsg_arr = array();
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);
$city = clean($_POST['city']);
$country = clean($_POST['country']);
$month = clean($_POST['month']);
$day = clean($_POST['day']);
$year = clean($_POST['year']);
$sex = clean($_POST['sex']);
$designers = clean($_POST['designers']);
$brands = clean($_POST['brands']);
$mags = clean($_POST['mags']);
$store = clean($_POST['store']);
$have = clean($_POST['have']);
$icon = clean($_POST['icon']);
$style = clean($_POST['style']);
$pants = clean($_POST['pants']);
$shirts = clean($_POST['shirts']);
$dress = clean($_POST['dress']);
$shoe = clean($_POST['shoe']);
if($fname == '') {
$errmsg_arr[] = 'First name is missing';
$errflag = true;
}
if($lname == '') {
$errmsg_arr[] = 'Last name is missing';
$errflag = true;
}
if($city == '') {
$errmsg_arr[] = 'City is missing';
$errflag = true;
}
if($country == '') {
$errmsg_arr[] = 'Country is missing';
$errflag = true;
}
if($sex == '') {
$errmsg_arr[] = 'Sex is missing';
$errflag = true;
}
if($month == '') {
$errmsg_arr[] = 'Month is missing';
$errflag = true;
}
if($day == '') {
$errmsg_arr[] = 'Day is missing';
$errflag = true;
}
if($year == '') {
$errmsg_arr[] = 'Year is missing';
$errflag = true;
}
if($designers == '') {
$errmsg_arr[] = 'Designers missing';
$errflag = true;
}
if($brands == '') {
$errmsg_arr[] = 'Brands missing';
$errflag = true;
}
if($mags == '') {
$errmsg_arr[] = 'Magazines missing';
$errflag = true;
}
if($store == '') {
$errmsg_arr[] = 'Favorite store missing';
$errflag = true;
}
if($have == '') {
$errmsg_arr[] = 'Must Have missing';
$errflag = true;
}
if($icon == '') {
$errmsg_arr[] = 'Icon missing';
$errflag = true;
}
if($style == '') {
$errmsg_arr[] = 'Your Style missing';
$errflag = true;
}
if($pants == '') {
$errmsg_arr[] = 'Pants size missing';
$errflag = true;
}
if($shirts == '') {
$errmsg_arr[] = 'Shirt size missing';
$errflag = true;
}
if($shoe == '') {
$errmsg_arr[] = 'Shoe size missing';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'Confirm password missing';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Passwords do not match';
$errflag = true;
}
if($login != '') {
$qry = "SELECT * FROM members WHERE login='$login'";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) > 0) {
$errmsg_arr[] = 'Login ID already in use';
$errflag = true;
}
@mysql_free_result($result);
}
else {
die("Query failed");
}
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: register-form.php");
exit();
}
$qry = "INSERT INTO members(login, passwd, firstname, lastname, month, day, year, sex, city, country, designers, brands, mags, store, have, icon,
style, pants, shirts, dress, shoe)
VALUES('$login','".md5($_POST['password'])."','$fname','$lname','$month','$day','$year','$sex','$city','$country','$designers','$brands','$mags','$store','$h
ave','$icon','$style','$pants','$shirts','$dress','$shoe')";
$result = @mysql_query($qry);
if($result) {
header("location: register-success.php");
exit();
}else {
die("Query failed");
}
?>
added code tags ~ CV