Hi
I have set up a page (computers_staff.php) with a comments form that when submitted
gets directed by a header function to a confirmation page which redirects
back to the comments page. This should avoid the form re-submitting
when the page is refreshed.
When I test the page in localhost everything works fine!
When I test online the page redirects back to the comments page but
does not show the form or previous comments, all that displays is my
included header. include("includes/header.php");
When I first load the site online and navigate to the comments page using the site
navigation the comments page displays the form and comments section as required.
It looks as if has something to do with the
header('Location: report_confirm.php');
which then
header('Location: computers_staff.php');
This is the full page -
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Make Me Elvis - Add Email</title>
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
</head>
<body>
<?php include("includes/header.php");
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_abe = "localhost";
$database_abe = "test";
$username_abe = "user";
$password_abe = "pass";
$abe = mysql_pconnect($hostname_abe, $username_abe, $password_abe) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_abe, $abe);
$query_staff_list = "SELECT * FROM computers ORDER BY name ASC";
$staff_list = mysql_query($query_staff_list, $abe) or die(mysql_error());
$row_staff_list = mysql_fetch_assoc($staff_list);
$totalRows_staff_list = mysql_num_rows($staff_list);
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$report = $_POST['report'];
//$resolved = $_POST['resolved'];
$output_form = 'no';
if (empty($name) || empty($report)) {
// We know at least one of the input fields is blank
echo 'Please fill out all of the email information.<br />';
$output_form = 'yes';
}
}
else {
$output_form = 'yes';
}
if (!empty($name) && !empty($report)) {
$dbc = mysqli_connect('localhost', 'user', 'pass', 'test')
or die('Error connecting to MySQL server.');
date_default_timezone_set('Europe/London');
$date = date('Y'-'m'-'d');
$query = mysql_query("INSERT INTO reports (name, report, date) VALUES ('$name', '$report', null)") or die(mysql_error());
mysqli_query($dbc, $query);
header('Location: report_confirm.php');
mysqli_close($dbc);
}
if ($output_form == 'yes') {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center"><tr><td valign="top">
<label for="name"></label><select name="name" id="name">
<?php
do {
?>
<option value="<?php echo $row_staff_list['name']?>"><?php echo $row_staff_list['name']?></option>
<?php
} while ($row_staff_list = mysql_fetch_assoc($staff_list));
$rows = mysql_num_rows($staff_list);
if($rows > 0) {
mysql_data_seek($staff_list, 0);
$row_staff_list = mysql_fetch_assoc($staff_list);
}
?>
</select></td><td>
<label for="report"></label><textarea name="report" id="report" cols="50" rows="8"></textarea></td></tr>
<tr><td> </td><td><input type="submit" name="submit" value="Submit" /></td></tr></table>
</form><br/>
<?php
$dbc = mysqli_connect('localhost', 'user', 'pass', 'test')
or die('Error connecting to MySQL server.');
$query = "SELECT * FROM reports ORDER BY date DESC";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
while( $row = mysqli_fetch_assoc($result)){
$id = $row['id'];
$name = $row['name'];
$report = $row['report'];
$date = $row['date'];
echo "<table align='center' border='1' width='80%'><tr><td>Computer / Laptop $name</td><td>Reported on $date</td></tr>
<tr><td colspan='2'>$report</td></tr></table>";
}
}
?>
</body>
</html>
Best regards Maxwell

New Topic/Question
Reply



MultiQuote





|