I am trying to register two different userinfo with dropdown but getting some error when i click on submit butto. I am newbie in php.Please help me solving this error...
My database is:
id int(2) Primary Key
type char(2)
cname varchar(55)
uname varchar(55)
mail varchar(55)
pswd varchar(55)
address varchar(255)
zip int(6)
regtime datetime
conn.php file
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$dbname = 'star';
$con = mysql_connect( $host,$user,$pass ) or die('Unable to connect');
mysql_select_db( $dbname ) or die('Unable to select database');
?>
register.php
<?php
require('include/conn.php'); //include db connection
$error = array(); //define $error to prevent error later in script
$message = '';
if ( isset( $_POST['submit'] ) ) {
$error = array();
array_map( 'stripslashes',$_POST ); //Strips slashes
array_map( 'mysql_real_escape_string',$_POST ); //Escapes data to protect against sql injection
$type = $_POST['utype'];
$company = $_POST['cname'];
$user = $_POST['uname'];
$email = $_POST['mail'];
$pass = $_POST['pswd'];
$address = $_POST['address'];
$zip = $_['zip'];
//usertype
if ( empty( $type ) ) { //check if type is selected on not
$error[] = 'Type not selected';
}
//company name
if ( empty( $company ) ) { //check if company name is blank
$error[] = 'Company not entered';
}
//username
if ( empty( $user ) ) { //check if username is blank
$error[] = 'Username is blank';
}
elseif ( strlen( $user ) > 30 ) { //make sure the username is not longer than 30 chars
$error[] = 'Username is longer than 30 characters';
}
else { //if there aren't any errors with $user at this point, check to make sure no one else has the same username
$query = mysql_query( "SELECT * FROM `users` WHERE `user` = '{$uname}'",$con );
if ( mysql_num_rows( $query ) > 0 ) {
$error[] = 'Username already exists';
}
}
//email
if ( empty( $email ) ) { //check if email is blank
$error[] = 'EMail not entered';
}
//password
if ( empty( $pass ) ) { //check if password is blank
$error[] = 'Password is blank';
}
elseif ( strlen( $pass ) < 9 ) { //make sure password is longer than 8 characters
$error[] = 'Password must be longer than 8 characters';
}
elseif ( !preg_match( "/^.*(?=.{3,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/",$pass ) ) { //check to see if its a valid password
$error[] = 'Password invalid - it must contain at least 1 number, 1 uppercase letter, 1 lowercase letter';
}
//address
if ( empty( $address ) ) { //check if address is blank
$error[] = 'Address not entered';
}
//zipcode
if ( empty( $zip ) ) { //check if username is blank
$error[] = 'Pincode not entered';
}
if ( count( $error ) == 0 ) { //if there are no errors, then insert into database
$pass = encryptPassword( $pass ); //hash password before inserting into database
$query = mysql_query( "INSERT INTO `users` (`type`,`cname`,`uname`,`mail`,`pswd`,`address`,`zip`) VALUES ('{$type}','{$company}','{$user}','{$email}','{$pass}','{$address}','{$zip}')",$con );
$message = 'User registration successful!';
}
}
$errmsg = '';
if ( count( $error ) > 0 ) { //if there are errors, build the error list to be displayed.
$errmsg = '<div>Errors:<br /><ul>';
foreach( $error as $err ) { //loop through errors and put then in the list
$errmsg .= "<li>{$err}</li>";
}
$errmsg .= '</ul></div>';
}
<html>
<head>
<title>Register</title>
</head>
<body>
<form action="{$_SERVER['PHP_SELF']}" class="form-horizontal" method="post">
<fieldset>
<legend>Sign Up | Basic Information </legend>
<label >Listing Type</label>
<div>
<select data-rel="chosen">
<option>Productin Unit</option>
<option>Vendor</option>
</select>
</div>
</div>
<label>Company Name</label>
<div >
<input type="text" name="cname" required="">
</div>
<div>
<label>Owner</label>
<div>
<input type="text" name="uname" required="">
</div>
</div>
<label >Email</label>
<div >
<input type="text" name="mail" required="">
</div>
<div>
<label >Choose Password</label>
<div >
<input type="password" name="pswd" required="">
</div>
</div>
<div>
<label>Confirm Password</label>
<div>
<input type="password" name="pswd" required="">
</div>
</div>
<div>
<label>Address</label>
<div>
<textarea name="address" rows="4"></textarea>
</div>
</div>
<div>
<label>Zip Code</label>
<div>
<input type="text" name="zip" required="">
</div>
</div>
<div >
<button type="submit" name="submit" >Next</button>
<button>Cancel</button>
</div>
</fieldset>
</form>
</body>
</html>
?>