Jump to content

[SOLVED] getting undefined index notice


riceje7

Recommended Posts

can't figure out why it seems to not be passing data through post method. i'm going from login.hml, the first bit of code, to processlogin.php, the second bit if code. any help woud be great. thanks

 

<html>
<head>
<title>Login Page</title>
</head>
<body>
<br>
<p><fieldset><legend align="center"><font face="helvetica" size="+2">Login</font></legend>
<form action="processlogin.php" method="post" enctype="text/plain" name="login">
<center>
Username: <input type="text" name="username" size="25" ><br><br>
Password: <input type="password" name="password" size="25"><br>
<input type="submit" name="submitlogin" value="Login">
</center>
</form>
</fieldset>
</p>
</body>
</html>

 

<?php
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);

$db = "";
$dbuser = "";
$dbpass = "";
$host = "";
$connect = mysql_connect($host, $dbuser, $dbpass) or die('Cannot connect to server');
mysql_select_db($db);

?>
<html>
<head>
<title>Process Login</title>
</head>

<body>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/180999-solved-getting-undefined-index-notice/
Share on other sites

and lose the enctype from the <form>, will solve your problem .. and while i'm at it, lose the <font> tags as they are deprecated.  use proper closing on your <br /> and <input />.

 

to shorten things up, just do:

 

$password = md5 ($_POST['password']);

 

and use mysql_real_escape_string() on your $_POST variables going to database:

 

<?php
$username = mysql_real_escape_string ($_POST['username']);
$password = md5 ($_POST['password']);
//etc...
?>

here are the errors:

Notice: Undefined index: username in /Volumes/coho/Users/ricej/Sites/nmd102/bio_project/processlogin.php on line 2

 

Notice: Undefined index: password in /Volumes/coho/Users/ricej/Sites/nmd102/bio_project/processlogin.php on line 3

and lose the enctype from the <form>

 

^it's not allowing you pass the $_POST variables.

 

make this change to your processlogin.php script:

 

<?php
if (isset ($_POST['submitlogin'])):
$username = mysql_real_escape_string ($_POST['username']);
$password = md5 ($_POST['password']);

$db = "";
$dbuser = "";
$dbpass = "";
$host = "";
$connect = mysql_connect($host, $dbuser, $dbpass) or die('Cannot connect to server');
mysql_select_db($db);

?>
<html>
	<head>
		<title>Process Login</title>
	</head>
	<body>
	</body>
</html>
<?php endif; ?>

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.