Undefined index error

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

sashmaira
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 19, 2012 10:46 pm

Undefined index error

Postby sashmaira » Sun Jan 22, 2012 10:34 pm

Good day, I have the following codes and I can't figure out the error, here it is:


<?php
$errorMessage = "";

//here goes the error
if($_POST['submit']){

if(empty($_POST['First_Name']))
{
$errorMessage .= "<li>First name required.</li>";
}
if(empty($_POST['Last_Name']))
{
$errorMessage .= "<li>Last name required.</li>";
}
if(empty($_POST['Username']))
{
$errorMessage .= "<li>Username required.</li>";
}
if(empty($_POST['passwd']))
{
$errorMessage .= "<li>Password required.</li>";
}
$fname = (isset($_POST['First_Name']) || trim($_POST['First_Name']) == "") ? die ('Enter First Name'):mysql_escape_string(trim($_POST['First_Name']));

$lname = (isset($_POST['Last_Name']) || trim($_POST['Last_Name']) == "") ? die ('Enter Last Name'):mysql_escape_string(trim($_POST['Last_Name']));

$username = (isset($_POST['Username']) || trim($_POST['Username']) == "") ? die ('Enter User Name'):mysql_escape_string(trim($_POST['Username']));

$password = (isset($_POST['passwd'])|| trim($_POST['passwd'])== "") ? die ('Enter Password'):mysql_escape_string(trim($_POST['passwd']));

$name = "$lname, $fname";

if(empty($errorMessage))
{
$con = mysql_connect('localhost','root','') or die ('unable to connect to mysql!');
mysql_select_db('users') or die ('unable to select database!');
$query = "INSERT INTO USER (name, username, password) VALUES (".$name.", ".$username.", ".$password.")";

$result = mysql_query($query, $con) or die ("Error in query: $query.".mysql_error());
header("Location: entries.php");
mysql_close($con);
exit();
}
}

function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}

// Quote
$value = "'" . mysql_real_escape_string($value) . "'";

return($value);
}

?>

// and here is my html script
<html>
<head>
<title>Users</title>
<!-- define some style elements-->
<style>
label,a
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}

</style>
</head>

<body>

<?php
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<fieldset>
<h1>Please register here</h1>
<div>
First Name: <input type="text" name='First_Name'/><br/>
Last Name: <input type="text" name='Last_Name' /><br />
Username:<input type="text" name='Username'/><br<label for="pw"><br>
Password:</label><input type="password" name='passwd' id="pw"size="20" /><br>
<input type="submit" name='sub' value="submit" />
</div>
</fieldset>
</form>
</body>
</html>

rupali
New php-forum User
New php-forum User
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Undefined index error

Postby rupali » Mon Jan 23, 2012 1:52 am

hello,

write like this as,

if(isset($_POST['submit']))

and, also in html code in the below line, you missed out to close line break tag
<br<label for="pw">

<br /><label for="pw">


Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron