jamkelvl Posted January 5, 2010 Share Posted January 5, 2010 Okay so I'll try to make this seem as simple as possible. It really is pretty simple... The below code simply deletes a specific file chosen by the user and also removes it from the database. The problem is when a user selects a page, for example: process.php and the below code will for some reason delete the last record in the database and the file associated with it rather than the selected page. <?PHP // Attempt database connection $connect = mysql_connect($hostname, $username, $password); if($connect == false){ echo('<p class="error">We are having technical difficulties and apologize for the inconvenience. Please try again later.</p>'); } // Select database $db = mysql_select_db($dbid); // Query the database $select = "SELECT * FROM pages"; $result = mysql_query($select); switch ($_GET['delete']) { case ($_GET['delete'] == "?") : echo "<h3>Select Page to Delete:</h3>"; while($row = mysql_fetch_array($result)){ extract($row); if ($type == "basic") { echo '<p> <a href="delete.php?delete='.$page.'"><img src="images/delbasp.jpg" width="125" height="125" alt="Edit '.$title.' Page" /></a> <p class="details"> <strong>Page Name:</strong> '.$page.'.php<br/> <strong>Title:</strong> '.$title.'<br/><br/><br/><br/><br/> <a href="delete.php?delete='.$page.'">Delete</a> </p> </p>'; } else { echo '<p> <a href="delete.php?delete='.$page.'"><img src="images/delgalp.jpg" width="125" height="125" alt="Edit '.$title.' Page" /></a> <p class="details"> <strong>Page Name:</strong> '.$page.'.php<br/> <strong>Title:</strong> '.$title.'<br/><br/><br/><br/><br/> <a href="delete.php?delete='.$page.'">Delete</a> </p> </p>'; } } break; case ($_GET['delete']) : //Check if user is trying to delete index page if ($page == "index") { echo '<h3>Error:</h3>'; echo '<p class="error">We are unable to delete this page.</p>'; echo "<meta http-equiv='refresh' content='1;URL=delete.php'>"; } else { //Delete the actual file $myFile = $page.".php"; unlink("../".$myFile); // Build query to delete row from table $delete = "DELETE FROM pages where title = '$title'"; echo $delete; $result = mysql_query($delete); if ($result == true) { echo ('<h3>Success!</h3><p class="success">Deleting '.$title.' page.'); echo "<meta http-equiv='refresh' content='1;URL=delete.php'>"; } else { echo '<p class="error">There was a problem deleting this page.</p>'; } } break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/187214-problem-deleting-rows/ Share on other sites More sharing options...
fenway Posted January 6, 2010 Share Posted January 6, 2010 Echo out the sql statements and you'll see what's being actually deleted. Quote Link to comment https://forums.phpfreaks.com/topic/187214-problem-deleting-rows/#findComment-989559 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.