Welcome! Log In Create A New Profile

Advanced

Register.php

Posted by dianajt 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Register.php
October 19, 2011 11:03AM
This is the code for my register.php page. If anyone has any tips to help improve my code please let me know. Thanks smiling smiley

Language: PHP
<?php session_start(); ob_start(); include "conn.inc.php"; ?>   <html> <head> <title>Register</title> </head>   <body> <?php   //print_r($_POST);   //gender radio buttons $male_status = 'unchecked'; $female_status = 'unchecked';   $gender = $_POST['gender']; // this line puts whichever radio button was selected into the variable   if ($gender == 'male') { $male_status = 'checked';   } else if ($gender == 'female') { $female_status = 'checked'; }   ///     //language radio buttons $eng = 'unchecked'; $afr = 'unchecked'; $xho = 'unchecked'; $zulu = 'unchecked'; $fre = 'unchecked';     $lang = $_POST['lang']; // this line puts whichever checkbox was selected into the variable   if (isset($_POST['lang'])) {   switch ($lang){   case 'eng': $eng = 'checked'; break;   case 'afr': $afr = 'checked'; break;   case 'xho': $xho = 'checked'; break;   case 'zulu': $zulu = 'checked'; break;   case 'fre': $fre = 'checked'; break; }   }   if (isset($_POST['submit']) && $_POST['submit'] == "Register"){ if ($_POST['username'] != "" && $_POST['password'] != "" && $_POST['sname'] != "" && $_POST['init'] != "" && $_POST['fname'] != "" && $_POST['title'] != "" && $_POST['msname'] != "" && $_POST['dob'] != "" && $_POST['gender'] != "" && $_POST['lang'] != "" && $_POST['idno'] != "" && $_POST['telh'] != "" && $_POST['telw'] != "" && $_POST['cel'] != "" && $_POST['email'] != "" && $_POST['fax'] != "" && $_POST['address'] != ""){   $query = "SELECT username FROM student WHERE username = '" . $_POST['username'] . "';"; $result = mysql_query($query) or die(mysql_error());   if (mysql_num_rows($result) != 0){ ?> <p> <font color="FF0000"><b>The Username, <?php echo $_POST['username']; ?>, is already in use, please choose another!</b> </font>     <FORM NAME="register" METHOD="POST" action="register.php">     Username: <INPUT type="text" VALUE="<?PHP print $_POST['username']; ?>" name="username" maxlength="40"> <br /><br />   Password: <INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40"> <br /><br />   Surname: <INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40"> <br /><br />   Initials: <INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40"> <br /><br />   First Name: <INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40"> <br /><br />   Title: <INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40"> <br /><br />   Maiden or Previous Surname: <INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40"> <br /><br />   Date of Birth: <INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40"> <br /><br />   Gender: <INPUT type="radio" name="gender" value='male' <?PHP print $male_status; ?>>Male   <INPUT type="radio" name="gender" value='female' <?PHP print $female_status; ?>>Female <br /><br />   Language for Correspondence: <br /> <INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English <br /> <INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans <br /> <INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa <br /> <INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu <br /> <INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre'] ; ?> name="lang">French   <br /><br />     Identity Number: <INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40"> <br /><br />   Telephone Number (H): <INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40"> <br /><br />   Telephone Number (W): <INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40"> <br /><br />   Cell Phone: <INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40"> <br /><br />   Fax Number: <INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40"> <br /><br />   Email: <INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40"> <br /><br />   Postal Address: <INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">     <INPUT TYPE="submit" Name="submit" VALUE="Register"> <input type="reset" value="Clear">     </FORM> </p>   <?php } else { //student table column names $sno = $_POST['sno']; $username = $_POST['username']; $password = $_POST['password']; $sname = $_POST['sname']; $init = $_POST['init']; $fname = $_POST['fname']; $title = $_POST['title']; $msname = $_POST['msname']; $dob = $_POST['dob']; $gender = $_POST['gender']; $lang = $_POST['lang']; $idno = $_POST['idno']; $telh = $_POST['telh']; $telw = $_POST['telw']; $cel = $_POST['cel']; $fax = $_POST['fax']; $email = $_POST['email']; $address = $_POST['address'];     //Create 'student' rows - add entries $sql_user_reg = "INSERT INTO student (sno,username, password, sname,init,fname,title,msname,dob,gender,lang,idno,telh,telw,cel,fax,email,address) VALUES ('$sno', '$username', '$password', '$sname','$init','$fname','$title','$msname','$dob','$gender','$lang','$idno','$telh','$telw','$cel','$fax','$email','$address')";   $user_reg_result = mysql_query($sql_user_reg) or die(mysql_error()); $_SESSION['user_logged'] = $_POST['username']; $_SESSION['user_password'] = $_POST['password']; ?>   <p> Thank you, <?php echo $_POST['fname'] . " " . $_POST['sname']; ?> for registering!<br />   <?php header("Refresh: 5; URL=index.php"); echo "Your registration is complete! " . "You are being sent to the page you requested!<br />"; echo "(If your browser doesn't support this, " . "<a href=\"index.php\"> click here </a>)"; die(); } } else{ ?> <p> <font color="FF0000"><b>The Username, Password, Email, First Name and Surname fields are required!</b> </font>     <FORM NAME="register" METHOD="POST" action="register.php">     Username: <INPUT type="text" VALUE="<?PHP print $_POST['username'] ; ?>" name="username" maxlength="40"> <br /><br />   Password: <INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40"> <br /><br />   Surname: <INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40"> <br /><br />   Initials: <INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40"> <br /><br />   First Name: <INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40"> <br /><br />   Title: <INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40"> <br /><br />   Maiden or Previous Surname: <INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40"> <br /><br />   Date of Birth: <INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40"> <br /><br />   Gender: <INPUT type="radio" name="gender" value='male' <?PHP print $male_status; ?>>Male   <INPUT type="radio" name="gender" value='female' <?PHP print $female_status; ?>>Female <br /><br />   Language for Correspondence: <br /> <INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English <br /> <INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans <br /> <INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa <br /> <INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu <br /> <INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre'] ; ?> name="lang">French   <br /><br />     Identity Number: <INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40"> <br /><br />   Telephone Number (H): <INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40"> <br /><br />   Telephone Number (W): <INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40"> <br /><br />   Cell Phone: <INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40"> <br /><br />   Fax Number: <INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40"> <br /><br />   Email: <INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40"> <br /><br />   Postal Address: <INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">     <INPUT TYPE="submit" Name="submit" VALUE="Register"> <input type="reset" value="Clear">     </FORM> </p> <?php } } else { ?> <p> Welcome to the registration page!<br /> The Username, Password, Email, First Name and Surname fields are required! <FORM NAME="register" METHOD="POST" action="register.php">   Username: <INPUT type="text" VALUE="<?PHP print $_POST['username'] ; ?>" name="username" maxlength="40"> <br /><br />   Password: <INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40"> <br /><br />   Surname: <INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40"> <br /><br />   Initials: <INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40"> <br /><br />   First Name: <INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40"> <br /><br />   Title: <INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40"> <br /><br />   Maiden or Previous Surname: <INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40"> <br /><br />   Date of Birth: <INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40"> <br /><br />   Gender: <INPUT type="radio" name="gender" value='male' <?PHP print $male_status; ?>>Male   <INPUT type="radio" name="gender" value='female' <?PHP print $female_status; ?>>Female <br /><br />   Language for Correspondence: <br /> <INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English <br /> <INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans <br /> <INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa <br /> <INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu <br /> <INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre']; ?> name="lang">French   <br /><br />     Identity Number: <INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40"> <br /><br />   Telephone Number (H): <INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40"> <br /><br />   Telephone Number (W): <INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40"> <br /><br />   Cell Phone: <INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40"> <br /><br />   Fax Number: <INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40"> <br /><br />   Email: <INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40"> <br /><br />   Postal Address: <INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">   <br /><br />   <INPUT TYPE="submit" Name="submit" VALUE="Register"> <input type="reset" value="Clear">     </FORM> </p> <?php } ?> </body> </html>
Re: Register.php
October 19, 2011 11:05AM
This is my register.php page. If anyone has any tips to help me improve my code please let me know. Thanks smiling smiley Diana Taylor

<?php
session_start();
ob_start();
include "conn.inc.php";
?>

<html>
<head>
<title>Register</title>
</head>

<body>
<?php

//print_r($_POST);

//gender radio buttons
$male_status = 'unchecked';
$female_status = 'unchecked';

$gender = $_POST['gender']; // this line puts whichever radio button was selected into the variable

if ($gender == 'male') {
$male_status = 'checked';

}
else if ($gender == 'female') {
$female_status = 'checked';
}

///


//language radio buttons
$eng = 'unchecked';
$afr = 'unchecked';
$xho = 'unchecked';
$zulu = 'unchecked';
$fre = 'unchecked';


$lang = $_POST['lang']; // this line puts whichever checkbox was selected into the variable

if (isset($_POST['lang'])) {

switch ($lang){

case 'eng':
$eng = 'checked';
break;

case 'afr':
$afr = 'checked';
break;

case 'xho':
$xho = 'checked';
break;

case 'zulu':
$zulu = 'checked';
break;

case 'fre':
$fre = 'checked';
break;
}

}

if (isset($_POST['submit']) && $_POST['submit'] == "Register"winking smiley{
if ($_POST['username'] != "" &&
$_POST['password'] != "" &&
$_POST['sname'] != "" &&
$_POST['init'] != "" &&
$_POST['fname'] != "" &&
$_POST['title'] != "" &&
$_POST['msname'] != "" &&
$_POST['dob'] != "" &&
$_POST['gender'] != "" &&
$_POST['lang'] != "" &&
$_POST['idno'] != "" &&
$_POST['telh'] != "" &&
$_POST['telw'] != "" &&
$_POST['cel'] != "" &&
$_POST['email'] != "" &&
$_POST['fax'] != "" &&
$_POST['address'] != ""winking smiley{

$query = "SELECT username FROM student WHERE username = '" . $_POST['username'] . "';";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) != 0){
?>
<p>
<font color="FF0000"><b>The Username,
<?php echo $_POST['username']; ?>, is already in use, please choose another!</b>
</font>


<FORM NAME="register" METHOD="POST" action="register.php">


Username:
<INPUT type="text" VALUE="<?PHP print $_POST['username']; ?>" name="username" maxlength="40"> <br /><br />

Password:
<INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40"> <br /><br />

Surname:
<INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40"> <br /><br />

Initials:
<INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40"> <br /><br />

First Name:
<INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40"> <br /><br />

Title:
<INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40"> <br /><br />

Maiden or Previous Surname:
<INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40"> <br /><br />

Date of Birth:
<INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40"> <br /><br />

Gender:
<INPUT type="radio" name="gender" value='male' <?PHP print $male_status; ?>>Male

<INPUT type="radio" name="gender" value='female' <?PHP print $female_status; ?>>Female <br /><br />

Language for Correspondence:
<br />
<INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English
<br />
<INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans
<br />
<INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa
<br />
<INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu
<br />
<INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre'] ; ?> name="lang">French

<br /><br />


Identity Number:
<INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40"> <br /><br />

Telephone Number (H):
<INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40"> <br /><br />

Telephone Number (W):
<INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40"> <br /><br />

Cell Phone:
<INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40"> <br /><br />

Fax Number:
<INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40"> <br /><br />

Email:
<INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40"> <br /><br />

Postal Address:
<INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">


<INPUT TYPE="submit" Name="submit" VALUE="Register">
<input type="reset" value="Clear">


</FORM>
</p>

<?php
} else {
//student table column names
$sno = $_POST['sno'];
$username = $_POST['username'];
$password = $_POST['password'];
$sname = $_POST['sname'];
$init = $_POST['init'];
$fname = $_POST['fname'];
$title = $_POST['title'];
$msname = $_POST['msname'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$lang = $_POST['lang'];
$idno = $_POST['idno'];
$telh = $_POST['telh'];
$telw = $_POST['telw'];
$cel = $_POST['cel'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$address = $_POST['address'];


//Create 'student' rows - add entries
$sql_user_reg = "INSERT INTO student (sno,username, password, sname,init,fname,title,msname,dob,gender,lang,idno,telh,telw,cel,fax,email,address)
VALUES ('$sno', '$username', '$password', '$sname','$init','$fname','$title','$msname','$dob','$gender','$lang','$idno','$telh','$telw','$cel','$fax','$email','$address')";

$user_reg_result = mysql_query($sql_user_reg) or die(mysql_error());
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
?>

<p>
Thank you, <?php echo $_POST['fname'] . " " .
$_POST['sname']; ?> for registering!<br />

<?php
header("Refresh: 5; URL=index.php"winking smiley;
echo "Your registration is complete! " .
"You are being sent to the page you requested!<br />";
echo "(If your browser doesn't support this, " .
"<a href=\"index.php\"> click here </a>winking smiley";
die();
}
} else{
?>
<p>
<font color="FF0000"><b>The Username, Password, Email, First Name and Surname fields are required!</b>
</font>


<FORM NAME="register" METHOD="POST" action="register.php">


Username:
<INPUT type="text" VALUE="<?PHP print $_POST['username'] ; ?>" name="username" maxlength="40"> <br /><br />

Password:
<INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40"> <br /><br />

Surname:
<INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40"> <br /><br />

Initials:
<INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40"> <br /><br />

First Name:
<INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40"> <br /><br />

Title:
<INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40"> <br /><br />

Maiden or Previous Surname:
<INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40"> <br /><br />

Date of Birth:
<INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40"> <br /><br />

Gender:
<INPUT type="radio" name="gender" value='male' <?PHP print $male_status; ?>>Male

<INPUT type="radio" name="gender" value='female' <?PHP print $female_status; ?>>Female <br /><br />

Language for Correspondence:
<br />
<INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English
<br />
<INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans
<br />
<INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa
<br />
<INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu
<br />
<INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre'] ; ?> name="lang">French

<br /><br />


Identity Number:
<INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40"> <br /><br />

Telephone Number (H):
<INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40"> <br /><br />

Telephone Number (W):
<INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40"> <br /><br />

Cell Phone:
<INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40"> <br /><br />

Fax Number:
<INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40"> <br /><br />

Email:
<INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40"> <br /><br />

Postal Address:
<INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">


<INPUT TYPE="submit" Name="submit" VALUE="Register">
<input type="reset" value="Clear">


</FORM>
</p>
<?php
}
} else {
?>
<p>
Welcome to the registration page!<br />
The Username, Password, Email, First Name and Surname fields are required!
<FORM NAME="register" METHOD="POST" action="register.php">

Username:
<INPUT type="text" VALUE="<?PHP print $_POST['username'] ; ?>" name="username" maxlength="40"> <br /><br />

Password:
<INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40"> <br /><br />

Surname:
<INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40"> <br /><br />

Initials:
<INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40"> <br /><br />

First Name:
<INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40"> <br /><br />

Title:
<INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40"> <br /><br />

Maiden or Previous Surname:
<INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40"> <br /><br />

Date of Birth:
<INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40"> <br /><br />

Gender:
<INPUT type="radio" name="gender" value='male' <?PHP print $male_status; ?>>Male

<INPUT type="radio" name="gender" value='female' <?PHP print $female_status; ?>>Female <br /><br />

Language for Correspondence:
<br />
<INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English
<br />
<INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans
<br />
<INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa
<br />
<INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu
<br />
<INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre']; ?> name="lang">French

<br /><br />


Identity Number:
<INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40"> <br /><br />

Telephone Number (H):
<INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40"> <br /><br />

Telephone Number (W):
<INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40"> <br /><br />

Cell Phone:
<INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40"> <br /><br />

Fax Number:
<INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40"> <br /><br />

Email:
<INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40"> <br /><br />

Postal Address:
<INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">

<br /><br />

<INPUT TYPE="submit" Name="submit" VALUE="Register">
<input type="reset" value="Clear">


</FORM>
</p>
<?php
}
?>
</body>
</html>
Re: Register.php
October 19, 2011 11:07AM
I just posted my register.php file. Sorry the message I wrote at the top of my code doen't seem to be displaying. If anyone has any tips to help improve my code please let me know. Thanks smiling smiley Diana
Re: Register.php
October 19, 2011 11:08AM
<?php
session_start();
ob_start();
include "conn.inc.php";
?>

<html>
<head>
<title>Register</title>
</head>

<body>
<?php

//print_r($_POST);

//gender radio buttons
$male_status = 'unchecked';
$female_status = 'unchecked';

$gender = $_POST['gender']; // this line puts whichever radio button was selected into the variable

if ($gender == 'male') {
			$male_status = 'checked';

		}
		else if ($gender == 'female') {
			$female_status = 'checked';
		}

///


//language radio buttons
$eng = 'unchecked';
$afr = 'unchecked';
$xho = 'unchecked';
$zulu = 'unchecked';
$fre = 'unchecked';


$lang = $_POST['lang']; // this line puts whichever checkbox was selected into the variable

 if (isset($_POST['lang'])) {
	
	switch ($lang){

		case 'eng':
		$eng = 'checked';
		break;
	
		case 'afr': 
		$afr = 'checked';
		break;
	
		case 'xho': 
		$xho = 'checked';
		break;
	
		case 'zulu': 
		$zulu = 'checked';
		break;
	
		case 'fre': 
		$fre = 'checked';
		break;
	}
	
}

if (isset($_POST['submit']) && $_POST['submit'] == "Register"winking smiley{
	if ($_POST['username'] != "" &&
		$_POST['password'] != "" &&
		$_POST['sname'] != "" &&
		$_POST['init'] != "" &&
		$_POST['fname'] != "" &&
		$_POST['title'] != "" &&
		$_POST['msname'] != "" &&
		$_POST['dob'] != "" &&
		$_POST['gender'] != "" &&
		$_POST['lang'] != "" &&
		$_POST['idno'] != "" &&
		$_POST['telh'] != "" &&
		$_POST['telw'] != "" &&
		$_POST['cel'] != "" &&
		$_POST['email'] != "" &&
		$_POST['fax'] != "" &&
		$_POST['address'] != ""winking smiley{
		
		$query = "SELECT username FROM student WHERE username = '" . $_POST['username'] . "';";
		$result = mysql_query($query) or die(mysql_error());
		
		if (mysql_num_rows($result) != 0){
?>
<p>		
<font color="FF0000"><b>The Username,
<?php echo $_POST['username']; ?>, is already in use, please choose another!</b>
</font>


<FORM NAME="register" METHOD="POST" action="register.php">


Username: 
  <INPUT type="text" VALUE="<?PHP print $_POST['username']; ?>" name="username" maxlength="40">  <br /><br />

Password: 
<INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40">  <br /><br />

Surname: 
<INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40">  <br /><br />

Initials: 
<INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40">  <br /><br />

First Name: 
<INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40">  <br /><br />

Title: 
<INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40">  <br /><br />

Maiden or Previous Surname: 
<INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40">  <br /><br />
 
Date of Birth: 
<INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40">  <br /><br />

Gender: 
<INPUT type="radio" name="gender"  value='male' <?PHP print $male_status; ?>>Male

<INPUT type="radio" name="gender"  value='female' <?PHP print $female_status; ?>>Female  <br /><br />
 
Language for Correspondence: 
<br />
<INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English
<br />
<INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans
<br />
<INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa
<br />
<INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu
<br />
<INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre'] ; ?> name="lang">French

<br /><br />


Identity Number: 
<INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40">  <br /><br />

Telephone Number (H):
<INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40">  <br /><br />
 
Telephone Number (W): 
<INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40">  <br /><br />
 
Cell Phone: 
<INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40">  <br /><br />

Fax Number: 
<INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40">  <br /><br />

Email: 
<INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40">  <br /><br />

Postal Address: 
<INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">

    
<INPUT TYPE="submit" Name="submit" VALUE="Register">
<input type="reset" value="Clear">


</FORM>
</p>

<?php
} else {
	//student table column names
	$sno = $_POST['sno']; 
	$username = $_POST['username'];
	$password = $_POST['password'];
	$sname = $_POST['sname'];
	$init = $_POST['init'];
	$fname = $_POST['fname'];
	$title = $_POST['title'];
	$msname = $_POST['msname'];
	$dob = $_POST['dob'];
	$gender = $_POST['gender'];
	$lang = $_POST['lang'];
	$idno = $_POST['idno'];
	$telh = $_POST['telh'];
	$telw = $_POST['telw'];
	$cel = $_POST['cel'];
	$fax = $_POST['fax'];
	$email = $_POST['email'];
	$address = $_POST['address'];


		//Create 'student' rows - add entries
		$sql_user_reg = "INSERT INTO student (sno,username, password, sname,init,fname,title,msname,dob,gender,lang,idno,telh,telw,cel,fax,email,address)
				VALUES ('$sno', '$username', '$password', '$sname','$init','$fname','$title','$msname','$dob','$gender','$lang','$idno','$telh','$telw','$cel','$fax','$email','$address')";

		$user_reg_result = mysql_query($sql_user_reg) or die(mysql_error());
		$_SESSION['user_logged'] = $_POST['username'];
		$_SESSION['user_password'] = $_POST['password'];
?>

<p>
	Thank you, <?php echo $_POST['fname'] . " " .
	$_POST['sname']; ?> for registering!<br />

<?php
	header("Refresh: 5; URL=index.php"winking smiley;
	echo "Your registration is complete! " .
		"You are being sent to the page you requested!<br />";
	echo "(If your browser doesn't support this, " .
	"<a href=\"index.php\"> click here </a>winking smiley";
	die();
	}
	} else{
?>
<p>
<font color="FF0000"><b>The Username, Password, Email, First Name and Surname fields are required!</b>
</font>


<FORM NAME="register" METHOD="POST" action="register.php">


Username: 
  <INPUT type="text" VALUE="<?PHP print $_POST['username'] ; ?>" name="username" maxlength="40">  <br /><br />

Password: 
<INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40">  <br /><br />

Surname: 
<INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40">  <br /><br />

Initials: 
<INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40">  <br /><br />

First Name: 
<INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40">  <br /><br />

Title: 
<INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40">  <br /><br />

Maiden or Previous Surname: 
<INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40">  <br /><br />
 
Date of Birth: 
<INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40">  <br /><br />

Gender: 
<INPUT type="radio" name="gender"  value='male' <?PHP print $male_status; ?>>Male

<INPUT type="radio" name="gender"  value='female' <?PHP print $female_status; ?>>Female  <br /><br />
 
Language for Correspondence: 
<br />
<INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English
<br />
<INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans
<br />
<INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa
<br />
<INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu
<br />
<INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre'] ; ?> name="lang">French

<br /><br />


Identity Number: 
<INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40">  <br /><br />

Telephone Number (H):
<INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40">  <br /><br />
 
Telephone Number (W): 
<INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40">  <br /><br />
 
Cell Phone: 
<INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40">  <br /><br />

Fax Number: 
<INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40">  <br /><br />

Email: 
<INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40">  <br /><br />

Postal Address: 
<INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">

    
<INPUT TYPE="submit" Name="submit" VALUE="Register">
<input type="reset" value="Clear">


</FORM> 
</p>
<?php
	}
} else {
?>
<p>
Welcome to the registration page!<br />
The Username, Password, Email, First Name and Surname fields are required!
<FORM NAME="register" METHOD="POST" action="register.php">

Username: 
  <INPUT type="text" VALUE="<?PHP print $_POST['username'] ; ?>" name="username" maxlength="40">  <br /><br />

Password: 
<INPUT type="text" VALUE="<?PHP print $_POST['password'] ; ?>" name="password" maxlength="40">  <br /><br />

Surname: 
<INPUT type="text" VALUE="<?PHP print $_POST['sname'] ; ?>" name="sname" maxlength="40">  <br /><br />

Initials: 
<INPUT type="text" VALUE="<?PHP print $_POST['init'] ; ?>" name="init" maxlength="40">  <br /><br />

First Name: 
<INPUT type="text" VALUE="<?PHP print $_POST['fname'] ; ?>" name="fname" maxlength="40">  <br /><br />

Title: 
<INPUT type="text" VALUE="<?PHP print $_POST['title'] ; ?>" name="title" maxlength="40">  <br /><br />

Maiden or Previous Surname: 
<INPUT type="text" VALUE="<?PHP print $_POST['msname'] ; ?>" name="msname" maxlength="40">  <br /><br />
 
Date of Birth: 
<INPUT type="text" VALUE="<?PHP print $_POST['dob'] ; ?>" name="dob" maxlength="40">  <br /><br />

Gender: 
<INPUT type="radio" name="gender"  value='male' <?PHP print $male_status; ?>>Male

<INPUT type="radio" name="gender"  value='female' <?PHP print $female_status; ?>>Female  <br /><br />
 
Language for Correspondence: 
<br />
<INPUT type="radio" VALUE='eng' <?PHP print $_POST['eng'] ; ?> name="lang">English
<br />
<INPUT type="radio" VALUE='afr' <?PHP print $_POST['afr'] ; ?> name="lang">Afrikaans
<br />
<INPUT type="radio" VALUE='xho' <?PHP print $_POST['xho'] ; ?> name="lang">Xhosa
<br />
<INPUT type="radio" VALUE='zulu' <?PHP print $_POST['zulu'] ; ?> name="lang">Zulu
<br />
<INPUT type="radio" VALUE='fre' <?PHP print $_POST['fre']; ?> name="lang">French

<br /><br />


Identity Number: 
<INPUT type="text" VALUE="<?PHP print $_POST['idno'] ; ?>" name="idno" maxlength="40">  <br /><br />

Telephone Number (H):
<INPUT type="text" VALUE="<?PHP print $_POST['telh'] ; ?>" name="telh" maxlength="40">  <br /><br />
 
Telephone Number (W): 
<INPUT type="text" VALUE="<?PHP print $_POST['telw'] ; ?>" name="telw" maxlength="40">  <br /><br />
 
Cell Phone: 
<INPUT type="text" VALUE="<?PHP print $_POST['cel'] ; ?>" name="cel" maxlength="40">  <br /><br />

Fax Number: 
<INPUT type="text" VALUE="<?PHP print $_POST['fax'] ; ?>" name="fax" maxlength="40">  <br /><br />

Email: 
<INPUT type="text" VALUE="<?PHP print $_POST['email'] ; ?>" name="email" maxlength="40">  <br /><br />

Postal Address: 
<INPUT type="text" VALUE="<?PHP print $_POST['address'] ; ?>" name="address" maxlength="40">

<br /><br />
    
<INPUT TYPE="submit" Name="submit" VALUE="Register">
<input type="reset" value="Clear">


</FORM> 
</p>
<?php
}
?>
</body>
</html>
Re: Register.php
October 19, 2011 11:10AM
It keeps removing the input fields for the form and just displays the name of the textbox infront of the input fields. Not sure how to change that? Sorry about posting so many times, was trying to get it right.
avatar Re: Register.php
October 19, 2011 11:31AM
Hi Diana

Are you inserting the code using the 'Formatted code' button (6th from the right on the message toolbar - little page with writing on it) or are you just copying and pasting?
avatar Re: Register.php
October 19, 2011 02:26PM
Hi Diana,

You have username and password fields... where are you storing those ? you know that the database structure has to stay the same.

student no: 77315138
avatar Re: Register.php
October 19, 2011 06:19PM
Also they need to sign up for a course :p
avatar
Mac
Re: Register.php
October 20, 2011 06:38AM
Use formatted code button to post code... make it way easier to read your code
Sorry, only registered users may post in this forum.

Click here to login