redarrow Posted June 12, 2006 Share Posted June 12, 2006 advance thank you.i want to use a link to delete a database entry but not a form how do i do that cheers.this comes from member page[code]<a href='delete_message.php?&id=".$record['sent_id']."'>Delete</a>[/code]delete.php seprate page[code]<? session_start();$db=mysql_connect("localhost" , "xxx" , "xxx");mysql_select_db("promotor",$db);$query="delete member_message where id=".$_GET['id']." ";$result=mysql_query($query);echo "deleted";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/ Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 As always, use mysql_error() to check if MySQL returns any error if it doesn't work. Remember that strings must always have quotes, so if your id is a string, use them:Mainly your query is incorrect:[code]$query="DELETE FROM member_message WHERE id='{$_GET['id']}'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/#findComment-44494 Share on other sites More sharing options...
redarrow Posted June 12, 2006 Author Share Posted June 12, 2006 if you want to only delete the members message of that users id but if time matchescheers.ps. it deletes all user rows to the id at the momentexample.[code]<? session_start();$db=mysql_connect("localhost" , "xxx" , "xxx");mysql_select_db("promotor",$db);$id=$_GET['id'];if($_GET["cmd"]=="delete"){$query="delete from member_messages where time='$time' and id='$id' ";echo $query;$result=mysql_query($query);echo "deleted";}?>[/code]echoed query[code]delete from member_messages where time='05:49:09' and id='0008' deleted [/code] Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/#findComment-44511 Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 Your query should work... There is the "AND" keyword, this should make it delete only rows with the specified id AND time.Are you sure this query deletes messages ignoring the time condition?700th post [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/#findComment-44516 Share on other sites More sharing options...
redarrow Posted June 12, 2006 Author Share Posted June 12, 2006 [!--quoteo(post=382750:date=Jun 12 2006, 04:57 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 12 2006, 04:57 AM) [snapback]382750[/snapback][/div][div class=\'quotemain\'][!--quotec--]Your query should work... There is the "AND" keyword, this should make it delete only rows with the specified id AND time.Are you sure this query deletes messages ignoring the time condition?700th post [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /][/quote]yes it deletes all messages from that users id but with time in place dosent delete at all. Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/#findComment-44522 Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 [!--quoteo(post=382756:date=Jun 11 2006, 10:15 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 11 2006, 10:15 PM) [snapback]382756[/snapback][/div][div class=\'quotemain\'][!--quotec--]yes it deletes all messages from that users id but with time in place dosent delete at all.[/quote]And that is the expect behavior, I guess.When there is time in place and nothing is deleted, this probably means no rows matching your criteria were found. What is the timestamp format you are using? Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/#findComment-44523 Share on other sites More sharing options...
redarrow Posted June 12, 2006 Author Share Posted June 12, 2006 working fine like this[code]<? session_start();$db=mysql_connect("localhost" , "root" , "admin");mysql_select_db("promotor",$db);$time=$_GET['time'];$id=$_GET['id'];if($_GET["cmd"]=="delete"){$query="delete from member_messages where time='$time' ";echo $query;$result=mysql_query($query);echo "deleted";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11761-post-to-delete/#findComment-44527 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.