Jump to content

I need help with my script


perezf

Recommended Posts

Im making a page that allow a user to choose the page he wants to edit from a drop down,

then he can edit the info for that page

 

for some reason its loading up a blank page, i think i have it write but can someone take a look and let me know if it is being done right :)

 

<?php
if ($_POST['choosepage']) {

if($_POST['Submit']) {

include ("../includes/dbconnect.inc.php");
$pageid = $_POST['pages'];
$heading = $_POST['pageheader'];
$information = $_POST['pageinfo'];

mysql_query("UPDATE pages SET pageheader = '$heading' WHERE pageid = '$pageid'");
mysql_query("UPDATE pages SET pageinfo = '$information' WHERE pageid = '$pageid'");

echo "Update Complete!";

} else {
include ("../includes/dbconnect.inc.php");
$pageid = $_POST['pages'];
$query = "SELECT * FROM pages WHERE pageid = '$pageid'"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>
<h1>Update Page</h1>
<form id="Submit" name="Submit" method="post" action="">
  <p>Heading:<br />
    <input name="pageheader" type="text" id="pageheader" size="50" value="<?php echo $row['pageheader']; ?>" />
  </p>
  <p>Information:   <br />
    <textarea name="pageinfo" cols="50" rows="15" id="pageinfo"><?php echo $row['pageinfo']; ?> </textarea>
  </p>
  <p>
    <input type="submit" name="Submit" value="Edit Page" />
  </p>
</form>

<?php
}
} else {
?>
<h1>Choose a Page</h1>
<form action="" method="post" name="pages">
<select name="pages">
  		<?php
		include ("../includes/dbconnect.inc.php");
				$query  = "SELECT pageid, pageheader, pageinfo FROM pages";
				$result = mysql_query($query);

				while($row = mysql_fetch_array($result, MYSQL_ASSOC))
				{
					echo "<option value=\"". $row['pageid'] ."\">".$row['pageheader']."</option>";
				} 

		?>
</select>
  <p>
    <label>
    <input type="submit" name="choosepage" id="choosepage" value="Choose Page" />
    </label>
  </p>
</form>
<?php } ?>

Link to comment
Share on other sites

Its very difficult to read your code due to its lack of indentation, however, these lines...

 

if ($_POST['choosepage']) {

 

should be...

 

if (isset($_POST['choosepage'])) {

 

Just another tip. These queries...

 

mysql_query("UPDATE pages SET pageheader = '$heading' WHERE pageid = '$pageid'");
mysql_query("UPDATE pages SET pageinfo = '$information' WHERE pageid = '$pageid'");

 

Should be done in one execution. eg;

 

mysql_query("UPDATE pages SET pageheader = '$heading', pageinfo = '$information' WHERE pageid = '$pageid'");

 

And you should really check it actually worked before displaying a success message. eg;

 

if (mysql_query("UPDATE pages SET pageheader = '$heading', pageinfo = '$information' WHERE pageid = '$pageid'")) {
  echo "Update Complete!";
}

Link to comment
Share on other sites

i organized the code so now can you help :)

<?php
if(isset($_POST['choosepage'])) {

		if(isset($_POST['editpage'])) {

			include ("../includes/dbconnect.inc.php");
			$pageid = $_POST['pages'];
			$heading = $_POST['pageheader'];
			$information = $_POST['pageinfo'];

			if (mysql_query("UPDATE pages SET pageheader = '$heading', pageinfo = '$information' WHERE pageid = '$pageid'")) {
			  echo "Update Complete!"; }


		} else {
			include ("../includes/dbconnect.inc.php");
			$pageid = $_POST['pages'];
			$query = "SELECT * FROM pages WHERE pageid = '$pageid'"; 
			$result = mysql_query($query) or die(mysql_error());
			$row = mysql_fetch_array($result) or die(mysql_error());
?>
<h1>Update Page</h1>
<form id="editpage" name="editpage" method="post" action="">
  	
  	<p>Heading:<br />
  		<input name="pageheader" type="text" id="pageheader" size="50" value="<?php echo $row['pageheader']; ?>" /></p>
  	
  	<p>Information:<br />
  		<textarea name="pageinfo" cols="50" rows="15" id="pageinfo"><?php echo $row['pageinfo']; ?> </textarea></p>
  	
  	<p><input type="submit" name="editpage" id="editpage" value="Edit Page" /></p>
  	
</form> 

<?php
                 }
} else {
?>
<h1>Choose a Page</h1>
<form action="" method="post" name="pages">

	<select name="pages">
  		     
  		    		                      <?php
						include ("../includes/dbconnect.inc.php");
						$query  = "SELECT pageid, pageheader, pageinfo FROM pages";
						$result = mysql_query($query);

						while($row = mysql_fetch_array($result, MYSQL_ASSOC))
						{
							echo "<option value=\"". $row['pageid'] ."\">".$row['pageheader']."</option>";
						} 
					?>

	</select>

  	<p><label><input type="submit" name="choosepage" id="choosepage" value="Choose Page" /></label></p>
  	
</form>

<?php }  ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.