Jump to content

Updating Page


j05hr

Recommended Posts

I'm trying to update a page that will save to the database.  It doesn't save it and just does the reload part of the code.

 

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php find_selected_page();?>
<?php
	if (intval($_GET['subj']) ==0) {
		redirect_to("content1.php");
	}

	if (isset($_POST['submit'])) {
		$errors = array();

		$required_fields= array('menu_name', 'position', 'visible', 'content');
		foreach($required_fields as $fieldname) {
			if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
				$errors[] = $fieldname;
			}
		}
		$fields_with_lengths = array('menu_name' => 30);
		foreach($fields_with_lengths as $fieldname => $maxlength ) {
			if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }

		}

		if (empty($errors)) {
			// Perform Update
			$id = mysql_prep($_GET['subj']);
			$menu_name = mysql_prep($_POST['menu_name']);
			$position = mysql_prep($_POST['position']);
			$visible = mysql_prep($_POST['visible']);
		}

		$query = "UPDATE subjects SET 
						menu_name = '{$menu_name}', 
						position = {$position}, 
						visible = {$visible} 
					WHERE id = {$id}";
			$result = mysql_query($query, $connection);
			if (mysql_affected_rows() == 1) {
				// Success
			} else { 
				// Failed
			}

	} else {
		// Errors occurred
	}


	 // end if (isset($_POST['submit'])) 
?>
<?php include("includes/header.php"); ?>
<div id="content">
	<h2> Buying Edit Page</h2>
	<br />
	<h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5>
		<form action="edit_subject.php?page=<?php echo urlencode($sel_subject['id']);?>" method="post">
			<p>Subject name: 
				<input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" />
			</p>
			<p>Edit content:
				<textarea name="content" rows="5" cols="70"><?php echo $sel_subject['content']; ?> </textarea>
				</p>
			<p>Position: 
				<select name="position">
					<?php
						$subject_set = get_all_subjects();
						$subject_count = mysql_num_rows($subject_set);
						// $subject_count + 1 b/c we are adding a subject
						for($count=1; $count <= $subject_count+1; $count++) {
							echo "<option value=\"{$count}\"";
							if ($sel_subject['position'] == $count) {
								echo " selected";
							} 
							echo ">{$count}</option>";
						}
					?>
				</select>
			</p>
			<p>Visible: 
				<input type="radio" name="visible" value="0"<?php 
				if ($sel_subject['visible'] == 0) { echo " checked"; } 
				?> /> No
				 
				<input type="radio" name="visible" value="1"<?php 
				if ($sel_subject['visible'] == 1) { echo " checked"; } 
				?> /> Yes
			</p>
			<input type="submit" name="submit" value="Edit Subject" />
		</form>
		<br/> 
		<a href="content1.php">Cancel</a>

<?php


?>
</div>
<?php require("includes/footer.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.