0

I have recently encountered dis error while doing <b>page validation</b> for my site.
I have been trying a lot ,but still could not find the solution.
Being a newbie to PHP, I would be obliged if u guys could help me out.
The URL of d site is,
http://www.dmcewriteups.co.cc/register.php

I do not understand,how all[except 1] errors vanish when I press reset button of the form
The HTML n PHP code is as follows :

<html>
<head>
<link href="style_register.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#474747">

<div id="form-container">
<center>
<h2>Registration form</h2>
</center>

<fieldset>
<form action = "register.php" method="POST">

<div class="error">
<?php
if($_POST['submit'])
{
	$username = $_POST['username'];
	$password = $_POST['password'];
	$name = $_POST['firstname'];
	$surname = $_POST['lastname'];
	$email = $_POST['email'];
	$mobile = $_POST['mobile'];
	$divroll = $_POST['divroll'];
	$key = $_POST['key'];
	$errorstring = "";

function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
	
	if(!$username)
		$errorstring = $errorstring."Username<br>";
	
	if(!$password)
		$errorstring = $errorstring."Password<br>";
		
	if(!$name)
		$errorstring = $errorstring."Name<br>";
		
	if(!$surname)
		$errorstring = $errorstring."Surname<br>";
		
	if(!$email)
		$errorstring = $errorstring."Email<br>";
		
	if(!mobile)
		$errorstring = $errorstring."Mobile<br>";
		
	if(!$divroll)
		$errorstring = $errorstring."Dive/Roll<br>";
		
	if(!$key)
		$errorstring = $errorstring."Key<br>";
		
	if($errorstring!="")
		echo "<h4>Please fill out the following fields:</h4>$errorstring"; 
		
	else
	{
		if($mobile.length<10 && ctype_digit($mobile))
			echo "Enter a valid mobile no.<BR>";
		
		if($username.length<4)
			echo "Enter a valid username<BR>";
		
		if($name.length <3)
			echo "Enter a valid First Name<BR>";

		if($surname.length <3)
			echo "Enter a valid Last Name<BR>";
			
		if($password.length <5 && ctype_alnum($password))
			echo "Enter a valid alphanumeric password<BR>";
			
		if($divroll.length>4 && ctype_alnum($divroll))
			echo "Enter a valid password<BR>";
			
		if (!valid_email($email))
			echo "Enter a valid email<BR>";
			
		if($key=="qazxsw123")
		{
			$connect=mysql_connect("mysql6.000webhost.com","XYZ","ABC");
			mysql_select_db("a3537046_info",$connect) or die (mysql_errno().":<b> ".mysql_error()."</b>");
			
			mysql_query("INSERT INTO users (username,password,name,surname,email,divroll,mobile) 
			VALUES('$username','$password','$name','$surname','$email','$divroll','$mobile')")or die(mysql_error());
			header("location:signin.html");
		}
		else
			echo "Enter a valid key<BR>";
	}	
}

if($_POST['reset'])
{
	$username = $_POST['username'];
	$password = $_POST['password'];
	$name = $_POST['firstname'];
	$surname = $_POST['lastname'];
	$email = $_POST['email'];
	$mobile = $_POST['mobile'];
	$divroll = $_POST['divroll'];
	$key = $_POST['key'];
	
	$username = "";
	$password = "";
	$name = "";
	$surname = "";
	$email = "";
	$mobile = "";
	$divroll = "";
	$key = "";
}

?>
</div>

<div class="field">
          <label for="username">Username :</label>
<input type='text' name='username' value = '<?php echo $username ?>'>
<div class ="example">example: john</div>
</div>

<div class="field">
          <label for="password">Password :</label>
<input type='password' name='password' value = '<?php echo $password ?>'>
<div class ="example">example: john123</div>
</div>

<div class="field">
          <label for="Name">First Name :</label>
<input name='firstname' type="text" value = '<?php echo $name ?>'>
</div>

<div class="field">
          <label for="Surname">Last Name :</label>
<input type='text' name='lastname' value = '<?php echo $surname ?>'>
</div>

<div class ="field">
          <label for="emailid">Email Id :</label>
<input type='text' name='email' value = '<?php echo $email ?>'>
<div class ="example">example: username@domain.com</div>
</div>

<div class ="field">
          <label for="mobile">Mobile No. :</label>
<input type='text' name='mobile' value = '<?php echo $mobile ?>'>
<div class ="example">example: 99XXXXXX09</div>
</div>

<div class ="field">
          <label for="divroll">Div/Roll No. :</label>
<input type='text' name='divroll' value = '<?php echo $divroll ?>'>
<div class ="example">example: A11</div>
</div>

<div class="field">
          <label for="key">Secret Key:</label>
<input type='text' name='key' value = '<?php echo $key ?>'>
<div class ="example">Ask admins !!!</div>
</div>

<div class="field">
<input class="submit-button" name = "submit" value="Submit" type="submit">
<input class="reset-button" name = "reset" value="Reset" type="submit">
</div>

</form>
</fieldset>
</div>
</body>
</html>

Edited by __avd: Added [code] tags.

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by atom6402
0

Your trying to print variables that aren't initialized. Try changing this:

if($_POST['reset'])
{
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['firstname'];
$surname = $_POST['lastname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$divroll = $_POST['divroll'];
$key = $_POST['key'];

$username = "";
$password = "";
$name = "";
$surname = "";
$email = "";
$mobile = "";
$divroll = "";
$key = "";
}

... to this ...

if($_POST['reset'])
{
  $username = $_POST['username'];
  $password = $_POST['password'];
  $name = $_POST['firstname'];
  $surname = $_POST['lastname'];
  $email = $_POST['email'];
  $mobile = $_POST['mobile'];
  $divroll = $_POST['divroll'];
  $key = $_POST['key'];
}
else
{
  $username = "";
  $password = "";
  $name = "";
  $surname = "";
  $email = "";
  $mobile = "";
  $divroll = "";
  $key = "";
}
0

@dcdruck - The problem hasnt solve ,after using ur code ........when i press reset ,i want all things types by user to be deleted but tht no more happens [which use to happen earlier]

Also i do not understand y i get d following error
Notice: Undefined index: submit in /home/a3537046/public_html/register.php on line 21


please help !!!

0

I changed the code for reset
from

if($_POST['reset'])
{
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['firstname'];
$surname = $_POST['lastname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$divroll = $_POST['divroll'];
$key = $_POST['key'];

$username = "";
$password = "";
$name = "";
$surname = "";
$email = "";
$mobile = "";
$divroll = "";
$key = "";
}

to

else
{
$username = "";
$password = "";
$name = "";
$surname = "";
$email = "";
$mobile = "";
$divroll = "";
$key = "";
}

and it worked abt error of uninitailise variables
But i am still not able to figure out error
"Notice: Undefined index: submit in /home/a3537046/public_html/register.php on line 21"

0

This problem has been solved by posted itself

You just need to put the

if($_POST['submit'])

as

if(isset($_POST['submit']))
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.