Jump to content

trouble w/ if statement


bradkenyon

Recommended Posts

Below I am trying to update values in a db table, which are plugged into an update form, to be updated.

 

Once I hit submit, it doesn't update.

 

I know connecting to the db is not a problem, I feel like the problem is something w/ the if statement of the if(!$_POST) and the one above that: if(mysql_num_rows($result)) and possibly if($result = mysql_query($sql)).

 

It seems like it ignores this part all together after hitting submit:

 

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());
		}

 

<?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))
	{
		// do the update
		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>';
	}

}
?>

 

Any help is appreciated, thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/119177-trouble-w-if-statement/
Share on other sites

craps out when i hit submit, so i feel like the if statement for checking if it was posted within the two other if statements to check the query results is messing it up, because if i remove those the test for checking to see if it is the correct author to update the entry, it works.

 

but i need that check, to make sure the person making the update is the appropriate person, if they are not, their update won't be approved (by approved, i mean the data they try submitting will not be entered into the db table in place of the original).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.