Ninjakreborn Posted October 10, 2006 Share Posted October 10, 2006 I have tried to replicate this a hundred times, but it never works, so I always leave it as is, it's always related to the cms.Every time I try to replicate something like this, it's suppose to show an edit form, allow them to edit, submit, then say it was successfull but still reshow the form everytime with the new information, but it NEVER works, I have tried this in hundreds of ways, within the past few months, every other time I need to build a cms I try to get it to work right, but it never does, it is confusing, any advice would be appreciated.[code]<?phpsession_start();// db connection infomysql_connect("localhost", "#####", "#####");mysql_select_db("hasbadse_hbservice");if ($_SESSION['controller'] == true) { if ($_POST['status'] == "edit") { $id = mysql_real_escape_string($_POST['id']); $header = mysql_real_escape_string($_POST['header']); $text = mysql_real_escape_string($_POST['text']); $edit = "UPDATE usercms SET header = '$header', text = '$text' WHERE id = '$id';"; if (mysql_query($edit)) { echo "Edited Successfully.<br />"; }else { echo "There was a problem editing this entry.<br />"; } }?><!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>Edit Your File Here</title></head><body><?phpif (isset($_GET['id']) || isset($id)) {$id = mysql_real_escape_string($_GET['id']);$select = "SELECT * FROM usercms WHERE id = '$id';";$query = mysql_query($select);if ($row = mysql_fetch_array($query)) {?><form name="edit" id="edit" action="usercpaneledit.php" method="post"><label for="header">Header:</label><br /><input name="header" id="header" type="text" maxlength="100" value="<?php echo $row['header']; ?>" /><br /><label for="text">Text:</label><br /><textarea name="text" id="text" rows="20" cols="20"><?php echo $row['text']; ?></textarea><br /><input name="status" value="edit" type="hidden" /><input name="id" value="<?php echo $row['id']; ?>" type="hidden" /><input name="submit" id="submit" type="submit" value="Continue" /></form><?php}?></body></html><?php }else { echo "You did not come from the proper page.<br />"; }}else {header("Location: index.php");}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23562-code-never-works/ Share on other sites More sharing options...
HuggieBear Posted October 10, 2006 Share Posted October 10, 2006 What parameters does this page get passed?Please provide all methods... GET/POST, COOKIES or SESSION.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23562-code-never-works/#findComment-106937 Share on other sites More sharing options...
Ninjakreborn Posted October 10, 2006 Author Share Posted October 10, 2006 Ok, anytime I do this kind of page, there are always the session variables for login, in this case they are $_SESSION['username'] = $username; $_SESSION['status'] = "logged"; $_SESSION['userid'] = $row['id']; $_SESSION['subdomainname'] = $row['subdomainname']; $_SESSION['email'] = $row['email']; $_SESSION['controller'] = true;Then it also get's past get statements from the previous page, in this case it's from a link, which Is the idthen when the post get's those variables are passed BACK to the same page, to start up the edit.Everything works, every time I do this, everything alway's work's properly.Except the bottom portion ALWAYS disappears when it does a successful one, this isn't the only way I have tried either, every time I build one I try to get the same functionality, it's like when it runs a database call php kills everything below it, it's aggravating. Quote Link to comment https://forums.phpfreaks.com/topic/23562-code-never-works/#findComment-106947 Share on other sites More sharing options...
HuggieBear Posted October 11, 2006 Share Posted October 11, 2006 Interesting use of both POST and GET, but not a problem... We can sort this for you.There's a few bits where I think you're over complicating it a bit, so we'll see if we can clear those up too.I'll get on the case now.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23562-code-never-works/#findComment-107335 Share on other sites More sharing options...
HuggieBear Posted October 11, 2006 Share Posted October 11, 2006 Businessman,Back up your old code and then give this a try. There's no real enhancements to the code, but it should work.[code]<?php// Start the sessionsession_start();// db connection infomysql_connect("localhost", "#####", "#####");mysql_select_db("hasbadse_hbservice");// Redirect if they aren't allowed to be hereif ($_SESSION['controller'] != true){ header("Location: index.php");}// If we don't have an ID then produce an error (I don't like this, but it's what you had it doing)if (!isset($_REQUEST['id']){ echo "You have arrived here from the wrong page\n"; die();}// If the status is edit then update the tableif ($_POST['status'] == "edit") { $id = mysql_real_escape_string($_POST['id']); $header = mysql_real_escape_string($_POST['header']); $text = mysql_real_escape_string($_POST['text']); $edit = "UPDATE usercms SET header = '$header', text = '$text' WHERE id = '$id'"; if (mysql_query($edit)){ echo "Edited Successfully.<br />"; } else { echo "There was a problem editing this entry.<br />"; }}// Select the data to display in the form$id = mysql_real_escape_string($_REQUEST['id']);$select = "SELECT * FROM usercms WHERE id = '$id'";$query = mysql_query($select);$row = mysql_fetch_array($query);// Echo the formecho <<<HTML<!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>Edit Your File Here</title> </head> <body> <form name="edit" id="edit" action="{$_SERVER['PHP_SELF']}" method="POST"> <label for="header">Header:</label><br /> <input type="text" name="header" id="header" maxlength="100" value="{$row['header']}" /><br /> <label for="text">Text:</label><br /> <textarea name="text" id="text" rows="20" cols="20">{$row['text']}</textarea><br /> <input type="hidden" name="status" value="edit" /> <input type="hidden" name="id" value="{$row['id']}" /> <input type="submit" name="submit" id="submit" value="Continue" /> </form> </body></html>HTML;?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23562-code-never-works/#findComment-107346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.