Hi guys, I wonder if someone can help me here about confirmation page. Basically I have 3 pages first, the main page (index.php) second the newForm.php (this form has two function create new user and modify the user) then the last one is confirmation page (confirmPage.php).
When user click a button either Create or Modify button on the newForm page, it will take them to the confirmation page so they can view all the data before proceed click to the main page.
Here is my confirm page but for some reason when I clicked button from the newForm page it will redirect me to the main page instead of going to the confirmation page first. Can someone please help me out.
Thanks.
<?php
session_start();
require 'includes/application.php';
if (!isset($_SESSION['mode'])) {
// if we get to this page without $_SESSION['mode'] being defined, we're in the wrong place...
exit("Invalid session data");
} else if ($_SESSION['mode'] == 'Modifying') {
// We are modfying the DB
$modify_sql = "UPDATE `persons` SET `name` = '".$_SESSION['name']."', `surname` = '".$_SESSION['surname']."', `address` = '".$_SESSION
['address']."', `mobile` = '".$_SESSION['mobile']."', `dept_id`= '".$_SESSION['dept']."' WHERE `id` = '".$_SESSION['id']."'";
mysql_query($modify_sql) or die (mysql_error());
// Redirect to indexPage.php
header("Location: indexPage_i.php?id=".$_SESSION['id']."&page=modify");
} else {
// We are creating a new entry
$create_sql = "INSERT INTO `persons` (`name`,`surname`,`dept_id`,`address`,`mobile`) VALUES ('".$_SESSION['name']."','".$_SESSION[
'surname']."','".$_SESSION['dept']."','".$_SESSION['address']."','".$_SESSION['mobile']."')";
mysql_query($create_sql) or die (mysql_error());
// Redirect to indexPage.php
header("Location: indexPage_i.php?id=".mysql_insert_id()."&page=create");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Confirmation Page</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<div align="center">
<table width="200" border="1">
<h1>Are You Happy With These Info?</h1>
<tr>
<th scope="row">First Name</th>
<td><?php echo $_SESSION['name'];?> </td>
</tr>
<tr>
<th scope="row">Surname</th>
<td><?php echo $_SESSION['surname'];?></td>
</tr>
<tr>
<th scope="row">Address</th>
<td><?php echo $_SESSION['address'];?></td>
</tr>
<!--Department Modify Form-->
<tr>
<th scope="row">Department</th>
<td>
<?php
$data = mysql_query ("SELECT dept_name FROM dept WHERE id = '".$_SESSION['dept']."'") or die (mysql_error());
$row_dept= mysql_fetch_array( $data );
$_SESSION['dept_name'] = $row_dept['dept_name'];
echo $_SESSION['dept_name'];
?>
</td>
</tr>
<!--End Department-->
<tr>
<th scope="row">Mobile</th>
<td><?php echo $_SESSION['mobile'];?> </td>
</tr>
<tr>
<td colspan="2" align="center"><p>
<br/ >
<input type="button" value="Back" onclick="history.go(-1)" />
<input type="hidden" name="mode" value="<?php echo $_SESSION['mode']; ?>">
<input type="submit" name="mode" value="<?php echo ($_SESSION['mode'] == "Creating") ? 'Create' : 'Modify'; ?>"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>