Right, I have a script (editpage.php) that takes a field form a table in a MySQL DB (SELECT content FROM content ....) It selects the correct row using the teamname. This team name is stored in a session variable ($_SESSION['username']).
It worked while I was using a separate form to ask which teamname should have it's content edited, but now that I am using sessions where a team can log in and edit ONLY their own content, this stops working!
No errors are displayed and the textarea element is displayed fine (exept that the current content is not there to edit). Everything is working (according to PHP and MySQL), but id kinda pointless as this page is called EDIT page, not CREATE page...
Here is the code:
<?php
// Do session stuff
// Start Session
session_start();
// Check that user is logged in
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
header("Location: login.php");
}
else{
// Require config
require('../config.php');
// Make requierd session vars useable
// $teamname = $_SESSION['username'];
// If config has no password
if(empty($mysqlPassword)){
// Connect to DB without password
$mysqlConnect = mysql_connect($mysqlHost, $mysqlUser);
}
// If config HAS a password
else{
// Connect to DB with password
$mysqlConnect = mysql_connect($mysqlHost, $mysqlUser, $mysqlPassword);
}
// Select DB
mysql_select_db($mysqlDB);
// If a form has been submitted
if(isset($_POST[submit])){
// Get form data
$newContent = $_POST[content];
}
// If new data has been entered
if(isset($newContent)){
// Prepare query
$setNewContent = "UPDATE $mysqlTablePrefix" . "content SET content = '$newContent' WHERE teamname = '" . $_SESSION['username'] . "'";
// Run query
$setNewContentResults = mysql_query($setNewContent);
// If content is successfully updated
if($setNewContentResults == TRUE){
// Set a message saying so
$message = 'Page successfully updated';
// Forward the user to index.php so that index.php can display this message
header("Location: index.php?message=$message");
}
// Else it has failed
else{
// Set a message saying so
$message = 'Page not updated. MySQL error:' . "\n" . mysql_error();
// Forward user to index.php so that index.php can display this message
header("Location: index.php?message=$message");
}
}
?>
<!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>
<title>The Blue School Council - Edit your Team's Page</title>
<base href="<?=$baseHREF; ?>" />
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable",
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator",
theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
content_css : "editpage.css",
plugin_insertdate_dateFormat : "%Y-%m-%d",
plugin_insertdate_timeFormat : "%H:%M:%S",
extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
file_browser_callback : "fileBrowserCallBack",
theme_advanced_resize_horizontal : false,
theme_advanced_resizing : true
});
</script>
<link rel="stylesheet" type="text/css" href="default.css" />
</head>
<body>
<div id="wrapper">
<div id="teamslist">
<ul>
<li><a href="index.php">Main Home</a></li>
<li><a href="teamadmin/">Admin Home</a></li>
<li><a href="teamadmin/editmenu.php">Edit a Menu Item</a></li>
<li><a href="teamadmin/editpage.php">Edit a Team's Page</a></li>
<li><a href="teamadmin/changepassword.php">Change your password</a></li>
<li><a href="teamadmin/logout.php">Logout</a></li>
</ul>
<div class="shade"></div>
</div>
<div id="text">
<form action="<?=$_SERVER[PHP_SELF]; ?>" method="post">
<?php
// If $newContent is not set yet...
if(!isset($newContent)){
// GET THE USER TO SET IT!!!
// Create form
// Prepare query
$getContent = 'SELECT content FROM ' . $mysqlTablePrefix . 'content WHERE teamname = \'' . $_SESSION['username'] . '\'';
// Run query
$getContentResults = mysql_query($getContent);
// Print into form
// Make $content an associative array (only contain content... lol)
$content = mysql_fetch_assoc($getContentResults);
// Echo a label for and a textarea containing the current code...
echo '<textarea name="content" rows="40" cols="80">' . $content[content] . '</textarea><br /><br />';
echo '<input type="submit" name="submit" value="Finish" />';
}
?>
</form>
<div class="shade"></div>
</div>
<div id="footer">
Back-end by <a href="http://thepeccavi.co.uk/">ThePeccavi</a><br />
For all other credits, see front end.
</div>
</div>
</body>
</html>
<?php
}
?>
Sorry about it's length!
Thanks in advance