Hello friends,
I am creating a registration form page.In that i have to edit and delete.So in edit page..I am getting the error.Here I will post the codings and let me know my queries...
If i am run the edit.php i am getting this error -" Error! "
<?php
function renderForm($id, $name, $email,$error)
{
?>
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div>
<p><strong>ID:</strong> <?php echo $id; ?></p>
<strong>Your Name: *</strong> <input type="text" name="name" value="<?php echo $name; ?>"/><br/>
<strong>email: *</strong> <input type="text" name="email" value="<?php echo $email; ?>"/><br/>
<p>* Required</p>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
<?php
}
// connect to the database
include('dbadmin.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
$email= mysql_real_escape_string(htmlspecialchars($_POST['email']));
if ($name == '' || $email == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($id, $name, $email,$error);
}
else
{
// save the data to the database
mysql_query("UPDATE login SET name='$name',email='$email' WHERE id='$id'")
or die(mysql_error());
header("Location: viewrec.php");
}
}
else
{
echo 'Error!';
}
}
else
{
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM login WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$name = $row['name'];
$email = $row['email'];
renderForm($id, $name,$email, '');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
{
echo 'Error!';
}
}
?>
thanks..