Jump to content

Recommended Posts

Dear All

I am new to php and working hard to learnning it need some help...I am creating a rigistration page and getting following errors....I am using WAMP and dreamweaver....I pasting my code and the error below please help me to resolve it.....:)

 

***ERRORS***

Notice: Undefined index: email in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 9

Notice: Undefined index: password in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 10

Notice: Undefined index: confirmpassword in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 11

Notice: Undefined variable: submit in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 15

 

***MY php CODE***

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Account Creation</title>
</head>

<body>
<?php
	$email = strip_tags ($_POST['email']);
	$password = strip_tags ($_POST['password']);
	$confirmpasswrod = strip_tags ($_POST['confirmpassword']);
	$date = date("y-m-d");

if ($submit)
{
			//check for existance

if ($email && $password && $confirmpasswrod)
{
if ($password == $confirmpasswrod)
{
			//check char lenght of email address
if (strlen ($email)>25)
	{
	echo
		"Length of username exceeds limit";
	}
	else
	{
			//check password lenght
if (strlen ($password)>25 || strlen ($password)<6)
	{
	echo
		"Password must be between 6 to 25 characters";
	}
	else
	{
			//register the user
			//encrypt password
		$password = MD5 ($password);
		$confirmpasswrod = MD5 ($confirmpasswrod);
	}
	}
	}
	else
	echo
		"Your password do not match!!!";
	}
	else 
	echo
	"Please fill in <b>all</b> feilds!!!";
	}

?>

<?php
include ("connect.php");
$queryreg = mysql_query("
insert into users values ('','$email','$password','$date')
");
?>


<form id= "regpage" method="post" name="regpage" action="regpage.php"
onsubmit= "return validate (regpage)">

<table width="282" border="0" align="center" style="padding-top:200px; padding-bottom:30px; padding-left:30px;">

<th align="center" style="padding-top:5px; padding-bottom:5px;"><font size="+2"><b>Registration Form</b></th>

<tr><td align="left" style=" padding-top:5px;padding-left:5px;"> Enter emial (username)<font color="#FF0000">*</font></td></tr>
<tr><td style=" padding-top:5px;padding-left:5px;">
<input name="email" type="text" size="40" maxlength="40"/> 
</td> </tr>

<tr><td align="left" style=" padding-top:5px;padding-left:5px;"> Enter Password<font color="#FF0000">*</font></td></tr> 
<tr><td style=" padding-top:5px;padding-left:5px;">
<input name="password" type="password" size="40" maxlength="40"/>
</td></tr>

<tr><td align="left" style=" padding-top:5px;padding-left:5px;"> Confirm Password <font color="#FF0000">*</font></td></tr> 
<tr><td style=" padding-top:5px;padding-left:5px;">
<input name="confirmpassword" type="password" size="40" maxlength="40"/>
</td></tr>

<tr>
<td align="center">
	<input type="submit" name="submit"value="Register">
	<input type="reset" value="Cancel">
</td>
</tr>

<tr>
<td style=" padding-top:5px;padding-left:5px;"><a  href="homepage.php">
<img src="Medical Imiges/Imiges/home.png" width="38" height="32" /></image>
</a></td></tr>

</table>
</form>

</body>
</html>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/240901-coding-errors/
Share on other sites

There are quite a few problems. One (which your errors point out) is that you never check to see if the form has been sent before you start accessing $_POST variables. Since you have the form submitting to itself, you need to check that the form was submit (Note: You should always check that the form was submit before you continue processing, but its crucial in forms that submit to the same page the form is on).

 

The most common way to check this is to check if the submit button has a value. First thing we must do it give the submit button a name and value in the form. You give your form the name submit and value register. We can check these by using isset(). Once we check it, we are safe to go ahead with the register code. However, if its not set, then we should display the form. This will result in the first visit to this page (to fill out the form) showing the form itself, without executing the register code (doesn't make sense to try to register them if they haven't even entered the information). then once they submit the form, it will execute the register code, and display any errors or a success message.

 

if (isset($_POST['submit'])){
//now we are safe to continue with the register
//here is where you should put your register code including the following
$email = $_POST['email'];
//etc...
}
else {
//now we know they havent submit the form, so we should display the form
?>
<form>
..html for form here
...
</form>
<?php 
}//this is the closing bracket for our else statement above
?>

 

the last error is talking about the if($submit) code. I think you were attempting to do something akin to what I did above, but got it all wrong. At that point in the code, there is no variable $submit. What happens is PHP makes this variable on the fly, and gives it a value of NULL, which will convert to boolean false when cast (which happens when you use it as the condition for the if statement). Try following the example I provided above, and remove this if statement, and that error should go away also

 

 

By the way, those "errors" (I referred to them as errors above, but incorrectly so) are actually notices. Notices don't end the execution on your PHP code, unlike errors which do. They are similar, but very different in that respect, and thus the code may act different if there is a notice (which usually indicate that there is something  that is bad programming wise, but doesn't break the script) versus if there is an error (something that basically forces the PHP interpreter into a state in which it cannot contiue execution).

Link to comment
https://forums.phpfreaks.com/topic/240901-coding-errors/#findComment-1237448
Share on other sites

There are quite a few problems. One (which your errors point out) is that you never check to see if the form has been sent before you start accessing $_POST variables. Since you have the form submitting to itself, you need to check that the form was submit (Note: You should always check that the form was submit before you continue processing, but its crucial in forms that submit to the same page the form is on).

 

The most common way to check this is to check if the submit button has a value. First thing we must do it give the submit button a name and value in the form. You give your form the name submit and value register. We can check these by using isset(). Once we check it, we are safe to go ahead with the register code. However, if its not set, then we should display the form. This will result in the first visit to this page (to fill out the form) showing the form itself, without executing the register code (doesn't make sense to try to register them if they haven't even entered the information). then once they submit the form, it will execute the register code, and display any errors or a success message.

 

if (isset($_POST['submit'])){
//now we are safe to continue with the register
//here is where you should put your register code including the following
$email = $_POST['email'];
//etc...
}
else {
//now we know they havent submit the form, so we should display the form
?>
<form>
..html for form here
...
</form>
<?php 
}//this is the closing bracket for our else statement above
?>

 

the last error is talking about the if($submit) code. I think you were attempting to do something akin to what I did above, but got it all wrong. At that point in the code, there is no variable $submit. What happens is PHP makes this variable on the fly, and gives it a value of NULL, which will convert to boolean false when cast (which happens when you use it as the condition for the if statement). Try following the example I provided above, and remove this if statement, and that error should go away also

 

 

By the way, those "errors" (I referred to them as errors above, but incorrectly so) are actually notices. Notices don't end the execution on your PHP code, unlike errors which do. They are similar, but very different in that respect, and thus the code may act different if there is a notice (which usually indicate that there is something  that is bad programming wise, but doesn't break the script) versus if there is an error (something that basically forces the PHP interpreter into a state in which it cannot contiue execution).

 

Now I have once again request for your kind assistance Mike would appreciate your help....

now I receive the following errors:

***ERRORS***

Notice: Undefined variable: email in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 58

Notice: Undefined index: email in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 100

Notice: Undefined index: password in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 100

Notice: Undefined variable: date in D:\wamp\www\phpprojects\capitalcityclinic\regpage.php on line 100

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Account Creation</title>
</head>

<body>

<form id= "regpage" method="post" name="regpage" action="regpage.php"
onsubmit= "return validate (regpage)">

<table width="282" border="0" align="center" style="padding-top:200px; padding-bottom:30px; padding-left:30px;">

<th align="center" style="padding-top:5px; padding-bottom:5px;"><font size="+2"><b>Registration Form</b></th>

<tr><td align="left" style=" padding-top:5px;padding-left:5px;"> Enter emial (username)<font color="#FF0000">*</font></td></tr>
<tr><td style=" padding-top:5px;padding-left:5px;">
<input name="email" type="text" size="40" maxlength="40"/> 
</td> </tr>

<tr><td align="left" style=" padding-top:5px;padding-left:5px;"> Enter Password<font color="#FF0000">*</font></td></tr> 
<tr><td style=" padding-top:5px;padding-left:5px;">
<input name="password" type="password" size="40" maxlength="40"/>
</td></tr>

<tr><td align="left" style=" padding-top:5px;padding-left:5px;"> Confirm Password <font color="#FF0000">*</font></td></tr> 
<tr><td style=" padding-top:5px;padding-left:5px;">
<input name="confirmpassword" type="password" size="40" maxlength="40"/>
</td></tr>

<tr>
<td align="center">
	<input type="submit" name="submit"value="Register">
	<input type="reset" value="Cancel">
</td>
</tr>

<tr>
<td style=" padding-top:5px;padding-left:5px;"><a  href="homepage.php">
<img src="Medical Imiges/Imiges/home.png" width="38" height="32" /></image>
</a></td></tr>

</table>
</form>
<?php

if (isset ($_POST['Submit']))
	{		
	$email = $_POST['email'];
	$password = $_POST['password'];
	$confirmpasswrod = $_POST['confirmpassword'];
	$date = date("y-m-d");
	}
else
{
			//check for existance

if ($email && $password && $confirmpasswrod)

{
if ($password == $confirmpasswrod)
{
			//check char lenght of email address
if (strlen ($email)>25)
		{
	echo
		"Length of email exceeds limit";
		}
	else
	{
			//check password lenght
if (strlen ($password)>25 || strlen ($password)<6)
		{
	echo
		"Password must be between 6 to 25 characters";
		}
	else
			{
			//register the user
			//encrypt password
		$password = MD5 ($password);
		$confirmpasswrod = MD5 ($confirmpasswrod);
			}
	}
}
	else
	echo
		"Your password do not match!!!";
	}
	else 
	echo
	"Please fill in <b>all</b> feilds!!!";
}
?>

<?php
include ("connect.php");
$queryreg = mysql_query("
insert into users values ('','".$_POST['email']."','".$_POST['password']."','$date')");
?>

</body>
</html>

 

please help....thank you...:)

Link to comment
https://forums.phpfreaks.com/topic/240901-coding-errors/#findComment-1237460
Share on other sites

thats not what I told you to do

if (isset ($_POST['Submit']))
	{		
	$email = $_POST['email'];
	$password = $_POST['password'];
	$confirmpasswrod = $_POST['confirmpassword'];
	$date = date("y-m-d");
	}
else
{

there should be no else here. The code in the else block is what you want to run if the isset() condition is true. all the register code should be inside the if statement block with the (isset($_POST['submit']) condition. The HTML Form is what should go in the else block per my example

Link to comment
https://forums.phpfreaks.com/topic/240901-coding-errors/#findComment-1237466
Share on other sites

thats not what I told you to do

if (isset ($_POST['Submit']))
	{		
	$email = $_POST['email'];
	$password = $_POST['password'];
	$confirmpasswrod = $_POST['confirmpassword'];
	$date = date("y-m-d");
	}
else
{

there should be no else here. The code in the else block is what you want to run if the isset() condition is true. all the register code should be inside the if statement block with the (isset($_POST['submit']) condition. The HTML Form is what should go in the else block per my example

 

 

 

Alright let me give it an another try...will inform u accordingly....

Link to comment
https://forums.phpfreaks.com/topic/240901-coding-errors/#findComment-1237556
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.