randal_138 Posted February 5, 2011 Share Posted February 5, 2011 My delete button will not work for some reason. I have created a loop, ordered my database entries with $i and have gotten closer, but not 100% of the way to making it work. I am trying to delete rows from my database individually. Not sure where I am going wrong with my syntax, but something is not working. The entries are not deleting nor am I receiving any errors. I am stumped. Here is the code. I shortened it for readability. <?php // database connection information include('connection.php'); $query = "SELECT * FROM FORUM_MESSAGE ORDER BY MSG_DATE DESC"; $result = mysql_query($query); $num = mysql_num_rows($result); $i = 0; while ($i < $num) { $subject = mysql_result ($result, $i, "SUBJECT"); $message_text = mysql_result ($result, $i, "MSG_TEXT"); echo '<form method="POST" name="subject">'; echo '<input type="hidden" name="update" value="<?php echo $subject; ?>" />'; echo '<input type="submit" name="update" value="Update" />'; echo ' '; echo '<input type="hidden" name="delete" value="' . $subject . '" />'; echo '<input type="submit" value="Delete" />'; echo '</form>'; $i++; } if (isset($_POST['delete'])) { include ('connection.php'); mysql_query("DELETE FROM FORUM_MESSAGE WHERE SUBJECT = " . $subject); } ?> </body> </html> Thanks again! Ryan Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Look at the color of the syntax highlighting in your post. Does anything jump out at you? Quote Link to comment Share on other sites More sharing options...
randal_138 Posted February 5, 2011 Author Share Posted February 5, 2011 I modified it so that it would be easier to read with only what I need to submit. I did try this: <?php include('connection.php'); $query = "SELECT * FROM FORUM_MESSAGE ORDER BY MSG_DATE DESC"; $result = mysql_query($query); $num = mysql_num_rows($result); mysql_close(); $i = 0; while ($i < $num) { $subject = mysql_result ($result, $i, "SUBJECT"); $message_text = mysql_result ($result, $i, "MSG_TEXT"); echo '<div style="width: 400px;padding:20px;">'; echo '<table border=0 width="400px">'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo '</td>'; echo '<td style="vertical-align:top;width:320px;text-align:center;">'; echo '<form method="POST" name="subject">'; echo '<input type="hidden" name="update" value="' . $subject . '" />'; echo '<input type="submit" name="update" value="Update" />'; echo ' '; echo '<input type="hidden" name="delete" value="' . $subject . '" />'; echo '<input type="submit" value="Delete" />'; echo '</form>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '<br />'; echo '<hr />'; echo '</div>'; $i++; } if (isset($_POST['delete'])) { include ('connection.php'); mysql_query("DELETE FROM FORUM_MESSAGE WHERE SUBJECT = " . $subject); } ?> That is what I am working with right now. I don't think the $subject and the actual button are connecting, but I can't point what exactly is wrong. Ryan 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.