son.of.the.morning Posted December 6, 2011 Share Posted December 6, 2011 I am delete records using $_POST on the current page using isset() function. The records are deleting and the isset function is working but the corresponding record still appears in the list of records until the page is reloaded again. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 6, 2011 Share Posted December 6, 2011 Code? Quote Link to comment Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 Sorry i forgot to add it in. if(isset($_GET['id'])) { $DeleteId = $_GET['id']; mysql_query("DELETE FROM blog_posts WHERE ID=$DeleteId") or die (mysql_error()); echo "Record #".$DeleteId." had been sucessfully deleted."; } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 6, 2011 Share Posted December 6, 2011 That isn't all of the relevant code for the problem you've described, but you should be checking to see if the query did in fact deleted anything by using mysql_affected_rows before echoing a success message. Quote Link to comment Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 Yea i know this, i am just tring to create the primary functions in. The other part of the code is a while loop that creats a list of records, each row containing a button that says delete with the url as... <a href"?id=<?php ehco $rows['id'] ?>">delete</a> it them returns the url and then i GET the var ID from the url using the code i showed on the previous post. Sorry i havnt explained my self very well here Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 6, 2011 Share Posted December 6, 2011 Without seeing all of the logic, there really isn't anything else I can think of at the moment. Quote Link to comment Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 I didnt want to post the code becuase there is quite a lot of it but here it is anyway <?php if(isset($_GET['id'])) { $DeleteId = $_GET['id']; mysql_query("DELETE FROM blog_posts WHERE ID=$DeleteId") or die (mysql_error()); echo "Record #".$DeleteId." had been sucessfully deleted."; } ?> <?php $rowNum = "0"; while($record_rows = mysql_fetch_array($records_returned)){ if(++$rowNum % 2 == 1 ) { ?> <form action="" method="post" name="DeleteSelected"> <div class="Record"> <div class="Thumbnail"><img src="../img/articles/thums/<?php echo $record_rows['img_url']; ?>" class="RecordThumbnail"/></div> <div class="RecordContent"> <div class="PostTitle"><strong><?php echo $record_rows['title']; ?></strong></div> <div class="CheckItem"> Select: <input name="DeleteItem<?php echo $record_rows['id']; ?>" type="checkbox" value="<?php echo $record_rows['id']; ?>" /> </div> <div class="PostSnipit"><?php echo substr($record_rows['post'], 0,50)."..."; ?></div> <div class="SelectOptions"> <div class="DeleteRecord" name="sub">Delete Article</div> <div id="VeiwRecord">Hide Details</div><div id="DeleteConfirm">Are you sure you would like to delete this record? <a href="?id=<?php echo $record_rows['id']; ?>" class="BlankLink"><input name="SingleRecordDelete" type="button" value="Yes." class="DeleteBtn" /></a> <input name="" type="button" value="No." class="DeleteBtn" id="HideDeleteOptions" /></div> <div id="ViewMoreHidden"> <div class="MoreText"><?php echo substr($record_rows['post'], 0,250)."..."; ?></div> <div class="PostedOn"><i><?php echo "Posted on: ".$record_rows['date_posted']; ?></i></div> </div> </div> </div> </div> <?php } else {?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2011 Share Posted December 6, 2011 The problem is not in the few lines of code that deletes the recored (that work's doesn't it) and the problem is not in the block of code that displays the data (that works doesn't it), the problem, if it is being caused by the code, is in the order in which the data is being deleted in the database table and when the data is being selected from the database table when the page is requested, which is why Pika asked for ALL the logic. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.