I have three pages in PHP that I would like to make into one. The first page takes the users info and submits it to the second page. The Second page takes the users info and displays it for their conformation. They user accepts the info and the info is sent to the third page which adds it to the MySQL database. I know its not the cleanest code you have ever seen.
Below is the code from the pages:
addmain.php
addmainconfirm.phpPHP Code:<?php
//check for admin session
//if no admin session, login
session_start();
if (!(isset($_SESSION['id']))) {
header ("Location:login.php");
}
?>
<!-- End check user login status-->
<?php
require ('includes/header.inc.php');
?>
<?php
require ('includes/nav.inc.php');
$usersubmit = $_REQUEST['usersubmit'];
if ($usersubmit == 1) {
$heading = $_POST['heading'];
$content = $_POST['content'];
$enter = 1;
}else{
// Get values from session variables
session_start();
$heading = $_SESSION['s_heading'];
$content = $_SESSION['s_content'];
}
if ($enter == 1) {
$newPage = "addmainconfirm.php";
$newPage .= "?heading=$heading";
$newPage .= "&content=$content";
echo "<script type\"text/javascript\">document.location = \"$newPage\"</script>";
}
?>
<div id="adminContent">
<form action="addmain.php?usersubmit=1" method="post">
<h3>Heading</h3>
<input name="heading" type="text" size="30" maxlength="100" />
<h3>Content</h3>
<textarea name="content" cols="60" rows="20"></textarea>
<input name="submit" type="submit" value="Add Main Topic" />
</form>
</div>
<?php
require ('includes/footer.inc.php');
?>
addmaindb.phpPHP Code:<?php
//check for admin session
//if no admin session, login
session_start();
if (!(isset($_SESSION['id']))) {
header ("Location:login.php");
}
require ('includes/header.inc.php');
require ('includes/nav.inc.php');
// Set local vars to the query string info
$heading = $_REQUEST['heading'];
$content = $_REQUEST['content'];
// Record user info in sessions
session_start();
$_SESSION['s_heading'] = $heading;
$_SESSION['s_content'] = $content;
?>
<div id="adminContent">
<?php
print "<h2>Confirmation</h2>";
print "<p>This is the information you have submitted</p>";
$addMainConfirm = "<p>Heading: $heading <br>\n";
$addMainConfirm .= "Content: $content <br>\n";
print $addMainConfirm;
print "<p><a href=\"addmain.php\">Make changes to the content</a><br />";
print "<a href=\"addmaindb.php\">Add this content now</a></p>";
?>
</div>
<?php
require ('includes/footer.inc.php');
?>
There are so many commonalities that I feel these should be on the same page. My question is how do I go about it. This is an area of PHP I'm not very good with (data flow)PHP Code:<?php
//check for admin session
//if no admin session, login
session_start();
if (!(isset($_SESSION['id']))) {
header ("Location:login.php");
}
require ('includes/header.inc.php');
require ('includes/nav.inc.php');
// Set local vars to the query string info
$heading = mysql_real_escape_string($_REQUEST['heading']);
$content = mysql_real_escape_string($_REQUEST['content']);
$heading = $_SESSION['s_heading'];
$content = $_SESSION['s_content'];
?>
<div id="adminContent">
<?php
require ('../includes/dbconnect.inc.php');
$sql = "INSERT INTO main (heading, content) values ('$heading', '$content')";
if (!($res = mysql_query($sql))) {
echo mysql_error();
}
?>
</div>
<?php
require ('includes/footer.inc.php');
?>
Thanks for your help in advance.![]()
If you need a live link to see how it works, let me know.







Bookmarks