i just want that after the updation (changes) it must be store in database , code is below plz help me as soon as possible in this topic
<?php
include("connect-db.php");
function renderForm($clientname = '', $address ='', $city = '', $telephoneno ='', $mobileno ='', $email = '', $sno ='', $userid = '')
{ ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
<?php if ($userid != '') { echo "Edit Record"; } else { echo "New Record"; } ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h1><?php if ($userid != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>
<?php if ($error != '') {
echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error
. "</div>";
} ?>
<form action="" method="post">
<div>
<?php if ($userid != '') { ?>
<input type="hidden" name="userid" value="<?php echo $userid; ?>" />
<?php } ?>
<table cellpadding="10" cellspacing="10" width="59%" align="center" border="0">
<tr>
<td>Client Name:</td>
<td><input type="text" name="clientname"
value="<?php echo $clientname; ?>"/></td>
</tr>
<br/>
<tr>
<td>Adress:</td>
<td> <input type="text" name="address"
value="<?php echo $address; ?>"/></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city"
value="<?php echo $city; ?>"/></td>
</tr>
<tr>
<td>Telephone no:</td>
<td> <input type="text" name="phoneno"
value="<?php echo $telephoneno; ?>"/></td>
</tr>
<tr>
<td>Mobile no:</td>
<td><input type="text" name="mobileno"
value="<?php echo $mobileno; ?>"/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email"
value="<?php echo $email; ?>"/></td>
</tr>
<tr>
<td>Sno:</td>
<td> <input type="text" name="sno"
value="<?php echo $sno; ?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php }
/*
EDIT RECORD
*/
// if the 'id' variable is set in the URL, we know that we need to edit a record
if (isset($_GET['userid']))
{
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit']))
{
// make sure the 'id' in the URL is valid
if (is_numeric($_POST['userid']))
{
// get variables from the URL/form
$userid = $_POST['userid'];
$clientname = htmlentities($_POST['clientname'], ENT_QUOTES);
$address = htmlentities($_POST['address'], ENT_QUOTES);
$city = htmlentities($_POST['city'], ENT_QUOTES);
$telephoneno = htmlentities($_POST['phoneno'], ENT_QUOTES);
$mobileno = htmlentities($_POST['mobileno'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
$sno = htmlentities($_POST['sno'], ENT_QUOTES);
if ($clientname == '' || $address == '' || $city == '' || $telephoneno == '' || $mobileno == '' || $email == '' || $sno)
{
$error = 'ERROR: Please fill in all required fields!';
renderForm($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno, $error, $userid );
}
else
{
// if everything is fine, update the record in the database
if ($stmt = $mysqli->prepare("UPDATE addclient SET clientname=$clientname, address=$address, city=$city, telephoneno=$telephoneno, mobileno=$mobileno, email=$email, sno=$sno WHERE userid=$userid"))
{
$stmt->bind_param("ssi", $clientname, $address, $city, $telephoneno, $mobileno, $email, $sno, $userid);
$stmt->execute();
$stmt->close();
}
// show an error message if the query has an error
else
{
echo "ERROR: could not prepare SQL statement.";
}
header("Location: view.php");
}
}
}
// if the form hasn't been submitted yet, get the info from the database and show the form
else
{
// make sure the 'id' value is valid
if (is_numeric($_GET['userid']) && $_GET['userid'] > 0)
{
// get 'id' from URL
$userid = $_GET['userid'];
// get the recod from the database
if($stmt = $mysqli->prepare("SELECT * FROM addclient WHERE userid= ?"))
{
$stmt->bind_param("i", $userid);
$stmt->execute();
$stmt->bind_result($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno,$userid);
$stmt->fetch();
// show the form
renderForm($clientname, $address, $city, $telephoneno,$mobileno,$email, $sno, NULL, $userid);
$stmt->close();
}
// show an error if the query has an error
else
{
echo "Error: could not prepare SQL statement";
}
}
// if the 'id' value is not valid, redirect the user back to the view.php page
else
{
header("Location: view.php");
}
}
}
/*
NEW RECORD
*/
// if the 'id' variable is not set in the URL, we must be creating a new record
else
{
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit']))
{
// get the form data
$clientname = htmlentities($_POST['clientname'], ENT_QUOTES);
$address = htmlentities($_POST['address'], ENT_QUOTES);
$city = htmlentities($_POST['city'], ENT_QUOTES);
$telephoneno = htmlentities($_POST['phoneno'], ENT_QUOTES);
$mobileno = htmlentities($_POST['mobileno'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
$sno = htmlentities($_POST['sno'], ENT_QUOTES);
// check that all fields are not empty
if ($clientname == '' || $address == '' || $city == '' || $telephoneno == '' || $mobileno == '' || $email == '' || $sno )
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno, $error);
}
else
{
// insert the new record into the database
if ($stmt = $mysqli->prepare("INSERT addclient (clientname, address, city, telephoneno, mobileno, email, sno) VALUES (?, ?, ?, ?, ?, ?, ?) where userid=?"))
{
$stmt->bind_param("ss", $clientname, $address, $city, $telephoneno, $mobileno, $email, $sno);
$stmt->execute();
$stmt->close();
}
// show an error if the query has an error
else
{
echo "ERROR: Could not prepare SQL statement.";
}
// redirec the user
header("Location: view.php");
}
}
// if the form hasn't been submitted yet, show the form
else
{
renderForm($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno);
}
}
// close the mysqli connection
$mysqli->close();
?>