princeofpersia Posted January 18, 2011 Share Posted January 18, 2011 Hi, Im using a button to delete each entry from my database, however it doesnt. I have tried it with linking to a delete page and works fine with the same mysql query, but i need to hve the button to delete and not a URL. Can someone please help me to see what is wrong? thanks in advance guys <?php include ("../include/global.php"); include ("../include/function.php"); if (loggedin()==FALSE) { Header("Location: ../login.php"); exit(); } $_SESSION['username']=='$username'; $username=$_SESSION['username']; $getid=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row=mysql_fetch_array($getid)) { $usersid=$row['id']; } if (isset($_POST['add']) && $_POST['add']) { $subject = addslashes(strip_tags($_POST['subject'])); $text = addslashes(strip_tags($_POST['text'])); $update=mysql_query("INSERT INTO users_notes (user_id, subject, note) VALUES ('$usersid','$subject','$text')"); } if (isset($_POST['remove']) && $_POST['remove']) { $delete=mysql_query("DELETE FROM users_notes WHERE user_id='$usersid' AND AND id='$id'"); } ?> <html> <head> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/jquery.validate.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#form").validate(); }); </script> </head> <body> <p>You are logged in! <a href="logout.php">Log out</a> </p> <p> </p> <p><td><? $getmsg=mysql_query("SELECT * FROM users_notes WHERE user_id='$usersid'"); while($row=mysql_fetch_array($getmsg)) { $id=$row['id']; $msgsubject=$row['subject']; $msgnotes=$row['note']; echo"<table width='800' border='1'>"; echo" <tr> <td width='50'>".$msgsubject."</td> <td width='50'>".$msgnotes."</td> <td width='40'><form id='form' method='post' action=''> <input type='submit' name='remove' value='remove' /> </form></td> <td> </td> </tr> "; } echo "</table>"; ?> </td> </p> <p> </p> <form action="" method="POST" id="form"> <p> Subject: <br/> <input type="text" name="subject" class="required"> </p> <p> Your Note: <br/> <textarea name="text" id="text" cols="45" rows="15" class="required"></textarea> </p> <p> <input type="submit" name="add" value="Add" > </p> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/ Share on other sites More sharing options...
coupe-r Posted January 18, 2011 Share Posted January 18, 2011 "DELETE FROM users_notes WHERE user_id='$usersid' AND AND id='$id' " You have 2 ANDs back to back for one Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161459 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 I see 2 issues that stick out: This will literally assign the string '$username' to sessions which ultimately is searched for in your query and it won't find anything. $_SESSION['username']=='$username'; In your DELETE query you have: AND AND id='$id'"); which is incorrect syntax. Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161460 Share on other sites More sharing options...
princeofpersia Posted January 18, 2011 Author Share Posted January 18, 2011 yeah ive done that i deleted one of the ANDs but still wont delete. I am aware of session issue, will resolve that later. Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161461 Share on other sites More sharing options...
coupe-r Posted January 18, 2011 Share Posted January 18, 2011 I don't see where you defined $id? echo that out and see what you get Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161464 Share on other sites More sharing options...
princeofpersia Posted January 18, 2011 Author Share Posted January 18, 2011 thats the id for msg note, its in the php inside the html <p> </p> <p><td><? $getmsg=mysql_query("SELECT * FROM users_notes WHERE user_id='$usersid'"); while($row=mysql_fetch_array($getmsg)) { $id=$row['id']; $msgsubject=$row['subject']; $msgnotes=$row['note']; echo"<table width='800' border='1'>"; echo" <tr> <td width='50'>".$msgsubject."</td> <td width='50'>".$msgnotes."</td> <td width='40'><form id='form' method='post' action=''> <input type='submit' name='remove' value='remove' /> </form></td> <td> </td> </tr> "; Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161465 Share on other sites More sharing options...
coupe-r Posted January 18, 2011 Share Posted January 18, 2011 add or die(mysql_error()) to the end of your query to see what mysql error you are getting. Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161470 Share on other sites More sharing options...
princeofpersia Posted January 18, 2011 Author Share Posted January 18, 2011 nothing at all, when i move the query just after where the form ends for remove, it deletes but it if i try to delete raw 1 it deletes raw 5 Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161471 Share on other sites More sharing options...
princeofpersia Posted January 18, 2011 Author Share Posted January 18, 2011 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161487 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 Did you fix this issue? $_SESSION['username']=='$username'; 1) You're using comparison, so you never assign that session variable to anything. 2) Even if you used assignment (=) you would be assigning the literal string '$username' and NOT the variable's value. Quote Link to comment https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/#findComment-1161501 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.