Need help with my script [NEED HELP STILL]
Posted: Sat Nov 29, 2008 4:41 am
hey guys, pleas help me xD
i am posting 2 pages. Ok so what i am basically doing is selecting a page to edit on the 1st page from a form, and then on the 2nd page i am editing it. Now the problem is that i am saught of picking up the data inside the 2nd page's edit form, but when select a page to edit from the 1st page, the data shows up, but if i go back and select another page it shows the same data, but if i go back and select another page again it will show that data. weird i know.
Also another error is that if i try to edit the data and press submit, it doesn't change.
BTW i am a noob to PHP and i have been using dreamweaver lol xD, but i am going to learn php
Page 1: edit_page.php
Page 2: edit_page_2.php
PLEASE HELP =]

i am posting 2 pages. Ok so what i am basically doing is selecting a page to edit on the 1st page from a form, and then on the 2nd page i am editing it. Now the problem is that i am saught of picking up the data inside the 2nd page's edit form, but when select a page to edit from the 1st page, the data shows up, but if i go back and select another page it shows the same data, but if i go back and select another page again it will show that data. weird i know.
Also another error is that if i try to edit the data and press submit, it doesn't change.
BTW i am a noob to PHP and i have been using dreamweaver lol xD, but i am going to learn php
Page 1: edit_page.php
Code: Select all
<?php require_once('../Connections/thinkdesignsconnectionstring.php'); ?><?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_thinkdesignsconnectionstring, $thinkdesignsconnectionstring);
$query_rsViewPages = "SELECT * FROM tblcontent";
$rsViewPages = mysql_query($query_rsViewPages, $thinkdesignsconnectionstring) or die(mysql_error());
$row_rsViewPages = mysql_fetch_assoc($rsViewPages);
$totalRows_rsViewPages = mysql_num_rows($rsViewPages);
?>
<!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"><!-- InstanceBegin template="/Templates/accessonly.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title></title>
<!-- InstanceEndEditable -->
<link href="accessonly.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<div id="container">
<div id="body">
<div id="banner"><img src="images/banner.gif" alt="" width="800" height="200" /></div>
<!-- InstanceBeginEditable name="main" -->
<div id="content"><br />
<br />
<br />
<br />
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" id="headingtable">
<tr>
<td width="95%" align="left"><h1>View Pages</h1></td>
</tr>
</table>
<a href="welcome.php">home</a> | <a href="add_page.php">add a page</a> | <a href="edit_page.php">edit/view a page</a> |<a href="<?php echo $logoutAction ?>">logout</a><br />
<br />
Below you can select the page you want to edit!<br />
<br />
<form action="edit_page_2.php" name="select&edit" id="select&edit">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td>PageID</td>
<td>PageName</td>
</tr>
<?php do { ?>
<tr>
<td><input type="radio" name="idradio" id="<?php echo $row_rsViewPages['PageID']; ?>" value="<?php echo $row_rsViewPages['PageID']; ?>" /></td>
<td><?php echo $row_rsViewPages['PageName']; ?></td>
</tr>
<?php } while ($row_rsViewPages = mysql_fetch_assoc($rsViewPages)); ?>
</table>
<br />
<input type="submit" value="Select & Edit" />
</form>
<br />
<br />
<br />
<br />
<br />
</div>
<!-- InstanceEndEditable --></div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsViewPages);
?>Page 2: edit_page_2.php
Code: Select all
<?php require_once('../Connections/thinkdesignsconnectionstring.php'); ?><?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE tblcontent SET PageName=%s, PageHeading=%s, Content=%s WHERE PageID=%s",
GetSQLValueString($_POST['PageName'], "text"),
GetSQLValueString($_POST['PageHeading'], "text"),
GetSQLValueString($_POST['Content'], "text"),
GetSQLValueString($_POST['PageID'], "int"));
mysql_select_db($database_thinkdesignsconnectionstring, $thinkdesignsconnectionstring);
$Result1 = mysql_query($updateSQL, $thinkdesignsconnectionstring) or die(mysql_error());
$updateGoTo = "welcome.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_rsEdit = "-1";
if (isset($_SESSION['sessionSE'])) {
$colname_rsEdit = $_SESSION['sessionSE'];
}
mysql_select_db($database_thinkdesignsconnectionstring, $thinkdesignsconnectionstring);
$query_rsEdit = sprintf("SELECT * FROM tblcontent WHERE PageID = %s", GetSQLValueString($colname_rsEdit, "int"));
$rsEdit = mysql_query($query_rsEdit, $thinkdesignsconnectionstring) or die(mysql_error());
$row_rsEdit = mysql_fetch_assoc($rsEdit);
$totalRows_rsEdit = mysql_num_rows($rsEdit);
?><?php $_SESSION["sessionSE"] = $_GET["idradio"];?>
<!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"><!-- InstanceBegin template="/Templates/accessonly.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title></title>
<!-- InstanceEndEditable -->
<link href="accessonly.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<div id="container">
<div id="body">
<div id="banner"><img src="images/banner.gif" alt="" width="800" height="200" /></div>
<!-- InstanceBeginEditable name="main" -->
<div id="content"><br />
<br />
<br />
<br />
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" id="headingtable">
<tr>
<td width="95%" align="left"><h1>Edit Page</h1></td>
</tr>
</table>
<a href="welcome.php">home</a> | <a href="add_page.php">add a page</a> | <a href="edit_page.php">edit/view a page</a> |<a href="<?php echo $logoutAction ?>">logout</a><br />
<br />
Below you can edit the current page you have selected.<br />
<br />
<p> </p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">PageID:</td>
<td><?php echo $row_rsEdit['PageID']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">PageName:</td>
<td><input name="PageName" type="text" value="<?php echo $row_rsEdit['PageName']; ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">PageHeading:</td>
<td><input name="PageHeading" type="text" value="<?php echo $row_rsEdit['PageHeading']; ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">Content:</td>
<td><textarea name="Content" cols="50" rows="5"><?php echo $row_rsEdit['Content']; ?></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Update record" /></td>
</tr>
</table>
<input type="hidden" name="PageID" />
<input type="hidden" name="MM_update" value="form1" />
</form>
<p> </p>
<br />
<br />
</div>
<!-- InstanceEndEditable --></div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsEdit);
?>