Notice: Undefined index: number in /Applications/MAMP/htdocs/CRUD_project/backend/luckyloves.php on line 71
Notice: Undefined index: email in /Applications/MAMP/htdocs/CRUD_project/backend/luckyloves.php on line 72
Notice: Undefined index: web in /Applications/MAMP/htdocs/CRUD_project/backend/luckyloves.php on line 73
for the Script :
<?php
//This is the Update and Create Page.
include('connection.php');
//Connect to the databae and then create the form function
//Make sure all variables are defined here
function renderForm($name = '', $number = '', $email = '', $web = '', $error = '', $id = '')
{ ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
<?php if($id != '') { echo "Edit A Love"; } else { echo "Create A New Love"; } ?>
</title>
</head>
<body>
<?php
// This is getting the errors and displaying them (If any)
if($error != '')
{
echo "<div style='padding:10px; border:1px solid red; color:red'/>" . $error . "</div>";
}
?>
<!-- Form to Process the Edit and Delete -->
<form action="" method="post">
<?php if($id != '') { ?>
<!-- We hide the id -->
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<?php } ?>
<p>Name:</p>
<input type="text" name="name" value="<?php echo $name; ?>"/>
<p>Number:</p>
<input type="text" name="name" value="<?php echo $number; ?>"/>
<p>Email:</p>
<input type="text" name="name" value="<?php echo $email; ?>"/>
<p>Web Address:</p>
<input type="text" name="name" value="<?php echo $web; ?>"/>
<br/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php }
//we check to see if the id is set
//if it is then we EDIT else we CREATE NEW
if(isset($_GET['id']))
{
//editing the exisitng record
renderForm(NULL, NULL, NULL, NULL, NULL, $_GET['id']);
}
else
{
//Create a new record
if(isset($_POST['submit']))
{
//htmlentities converts all characters to html entities.
//ENT_QUOTES will prevent SQL injections
$name = htmlentities($_POST['name'], ENT_QUOTES);
$number = htmlentities($_POST['number'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
$web = htmlentities($_POST['web'], ENT_QUOTES);
if($name == '' || $number == '' || $email == '' || $web == '')
{
$error = 'ERROR: Please fill in all required fields';
//error above displayed, but we dont want the user to reenter
//the fields so we present the form with the already entered
//results from above.
renderForm($name, $number, $email, $web, $error);
}
}
else
{
renderForm();
}
}
?>Can anyone see where im going wrong? Im stating the variables within the renderForm function I cannot understand why im getting these Notices.
Kind Regards.

Help












