Jump to content


Photo

code never works


  • Please log in to reply
4 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 October 2006 - 03:55 PM

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.

<?php
session_start();
// db connection info
mysql_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>
<?php
if (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");
}
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 October 2006 - 04:01 PM

What parameters does this page get passed?

Please provide all methods... GET/POST, COOKIES or SESSION.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 October 2006 - 04:06 PM

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 id
then 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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 11 October 2006 - 09:56 AM

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.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 11 October 2006 - 10:26 AM

Businessman,

Back up your old code and then give this a try.  There's no real enhancements to the code, but it should work.

<?php
// Start the session
session_start();

// db connection info
mysql_connect("localhost", "#####", "#####");
mysql_select_db("hasbadse_hbservice");

// Redirect if they aren't allowed to be here
if ($_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 table
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 />";
   }
}

// 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 form
echo <<<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;
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users