Jump to content

[SOLVED] ignoring post method, to post variables into db table


bradkenyon

Recommended Posts

I have a page that allows you to update entries, but it checks to make sure you're the author of that entry.

<?php
$id = $_GET['id'];
$author = $HTTP_SESSION_VARS['valid_username'];
$sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '$author'";

if($result = mysql_query($sql))
{
	if(mysql_num_rows($result))
	{
		if(!$_POST)
		{

			$queryupd = "select * from calendar_items where id = $id";

			$resultupd=mysql_query($queryupd);

			?>
			<div class="details">
			<?php
			while($rowupd = mysql_fetch_array($resultupd))
			{
				?>

				<form enctype="multipart/form-data" method="post" action="<?=$_SERVER["PHP_SELF"]?>">
				<?php
					print '<input type="hidden" name="id" value="'.$rowupd['id'].'">';

					print '<h3>Event Title</h3>';
					print '<input type="text" name="subj" size="60" value="'.htmlentities($rowupd['subj']).'">';

					print	'<p><input type="Submit" value="Submit" name="Submit">
							<a href="/cms/">Cancel</a>
							</form>';
			}
		}
		else
		{

			$id=$HTTP_POST_VARS['id'];
			$subj=addslashes($HTTP_POST_VARS['subj']);

			$result = mysql_query("UPDATE calendar_items SET subj='$subj' WHERE id=$id") 
				or die(mysql_error());
		}
	} 
	else
	{
		// display your unauthorised message
		print '
			<div class="alert">
				To update, you need to be author of event.
			</div>';
	}
} 
?>

 

When I hit submit, it does not work. I think the if(!$_POST) might be the problem.

 

The way it should work: if the form was not posted, then display the form w/ the current data, if it was posted, then grab the values within the form fields and update them in the db table, then display the form w/ the updated values.

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.