bradkenyon Posted August 11, 2008 Share Posted August 11, 2008 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 More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 Try if ( empty($_POST) ) Link to comment https://forums.phpfreaks.com/topic/119177-trouble-w-if-statement/#findComment-613761 Share on other sites More sharing options...
bradkenyon Posted August 11, 2008 Author Share Posted August 11, 2008 thanks for the suggestion, tried, no luck. I think it has something to w/ this part of the code: if($result = mysql_query($sql)) { if(mysql_num_rows($result)) { Link to comment https://forums.phpfreaks.com/topic/119177-trouble-w-if-statement/#findComment-613766 Share on other sites More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 Possibly. Try outputting all data you're checking and make sure it's the data you expect. Link to comment https://forums.phpfreaks.com/topic/119177-trouble-w-if-statement/#findComment-613770 Share on other sites More sharing options...
bradkenyon Posted August 11, 2008 Author Share Posted August 11, 2008 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). Link to comment https://forums.phpfreaks.com/topic/119177-trouble-w-if-statement/#findComment-613790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.