Jump to content

User Registeration , please help !


evry1falls

Recommended Posts

i have done the register.php fileand it is now wokin as i want to . the problm is that when i tested it along with the register.html file i found out the User can leave the 'username' blank als the 'password' though both are set as "NOT NULL" .... please help me o set the register.php the right way not to enable someone from registering without leavin a blank 'usernme' or 'password' .... here is the script :

 

 

 

<?php 
include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';"; 
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 

//if the username already exists.
if ($num_rows != 0) {
include ("register.html");
echo "Sorry, the username <font color=blue size=+2 face=OrsonsHand> '$username' </font> is already taken.<br>";
echo "<center /><font face=orsonshand size=+2 color=blue><a href=register.html>Try again</a></font>";
exit; 
} else {

// if the username doesn't exists insert the data.
$insert = mysql_query("insert into $table 
values ('NOT NULL', '".$_POST['username']."', '".$_POST['password']."')")
or die("Could not insert data because ".mysql_error());

// print a success message
echo "<font color=red>Welcome</font>  ";
echo "<font color=blue size=+2 face=OrsonsHand>$username</font>" ;
echo " <font color=red>Your user account has been created!</font><br>"; 
}
mysql_close($link);
?>

 

and here i the register.html :

 

<html>
<head>
<title>User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #000000;
}
.style1 {
font-size: 36px;
font-weight: bold;
color: #4579B0;
}
.style3 {
color: #365F89;
font-weight: bold;
font-size: 18px;
}
.style6 {font-size: 14px; color: #3B6797; font-weight: bold; }
#Layer1 {
position:absolute;
left:13px;
top:143px;
width:100px;
height:700px;
z-index:1;
}
#Layer2 {
position:absolute;
left:29px;
top:865px;
width:1063px;
height:50px;
z-index:2;
background-color: #000000;
}
.style8 {
font-size: 24px;
color: #3C6793;
}
.style11 {
font-family: OrsonsHand;
font-weight: bold;
}
#Layer3 {
position:absolute;
left:12px;
top:385px;
width:100px;
height:64px;
z-index:3;
}
.style12 {
color: #7AABDE;
font-size: 12px;
font-weight: bold;
}
a:link {
color: #3F6D9C;
text-decoration: none;
}
a:visited {
color: #8BB6E2;
text-decoration: none;
}
a:hover {
color: #D1E2F4;
text-decoration: none;
}
a:active {
color: #243E58;
text-decoration: none;
}
.style13 {
font-size: 18px;
font-family: OrsonsHand;
}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<body>
<div id="Layer1"><img src="../project/TITLEa.png" width="100" height="700"></div>
<div id="Layer3">
  <div align="center">
    <p class="style12">Already a member</p>
    <p class="style12"><a href="index.php" class="style13">Log in</a> </p>
  </div>
</div>
<div align="center">
  <p><img src="../project/tit.png" width="1103" height="53"></p>
</div>
<p align="center" class="style1">Register Now</p>
<div align="center"><table width="285" height="185">
<form action="register.php" method="post">
<tr>
<td width=""><div align="center" class="style3">
  <div align="left">Pick an ID :</div>
</div></td><td width="120"><div align="center">
  <input name="username" type="text" size="20">
</div></td>
</tr>
<tr>
<td class="style3"><div align="left">Password :</div></td><td>
  <div align="center">
    <input type="password" name="password" size="20">
  </div></td>
</tr><tr><td><input name="Register" type="submit" class="style6" value="Register"></td></tr></form></table>
</div>
<div align="center"></div>
<div id="Layer2">
  <hr align="center">
  <p align="center" class="style4 style8">©<span class="style11">Ahmed Samir</span></p>
</div>
</body>
</html>

please help ....... when i test the register " when i leave both usernme and password empty " it resgisters succefully and this is something i reallydon't want !

Link to comment
https://forums.phpfreaks.com/topic/56391-user-registeration-please-help/
Share on other sites

I use this code for my online application to check for blank fields. you can change it to work with your page ..

 

if (empty($lastname) or empty($middle) or empty($firstname) or empty($address) or empty($address_continue) or empty($city) or empty($state) or empty($zip) or empty($phone) or empty($email) or empty($position)) {
	$_SESSION['validate'] = "<font color = red>Please fill in all the required fields</font>";
	header ("Location: o_application.php");
}else{

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.