can we use mysql(DELETE...) query in the same page while having anchor tags?

Thread Solved

Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #1
Jul 7th, 2008
Hi all,

Instead of passing the variables to the other page and coding mysql queries there.. Is it possible that we can use the mysql(DELETE...) query within the anchor tags in the same page?

<a href >... to delete a particular row in mysql table?
Like having a link called delete and by clicking on that , a particular row must be deleted in the table.

eg:- <a href = " .... some mysql query....">DELETE</a>
(or)
eg:- <a href="<?php //delete this row ?>">delete</a>
(or)

eg:-
  1.  
  2. <?php
  3. //db connections..
  4.  
  5. $result = mysql_query("SELECT commentid FROM comments")
  6. or die(mysql_error());
  7.  
  8. while($row = mysql_fetch_array( $result )) {
  9. ?>
  10. <a href="<?php //delete this row ?>">delete</a>
  11. <?php } ?>

Instead of passing the variables to the other page and coding mysql queries there.. Is it possible that we can use the mysql(DELETE...) query in the same page?
I was wondering if there is some possibility like this in PHP .
Please let me know if there are any such methods .

Thankyou all in Advance.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
1
  #2
Jul 8th, 2008
Originally Posted by Kavitha Butchi View Post
  1.  
  2. <?php
  3. //db connections..
  4.  
  5. $result = mysql_query("SELECT commentid FROM comments")
  6. or die(mysql_error());
  7.  
  8. while($row = mysql_fetch_array( $result )) {
  9. ?>
  10. <a href="<?php //delete this row ?>">delete</a>
  11. <?php } ?>



Instead of passing the variables to the other page and coding mysql queries there.. Is it possible that we can use the mysql(DELETE...) query in the same page?
I was wondering if there is some possibility like this in PHP .
Please let me know if there are any such methods .

Thankyou all in Advance.
sure,you can,get the id of that you want to delete then perform the delete query in the same page.for example:
(this is your page,e.g. sample.php)
  1. <?php
  2. //db connections..
  3.  
  4. $result = mysql_query("SELECT commentid FROM comments")
  5. or die(mysql_error());
  6.  
  7. while($row = mysql_fetch_array( $result )) {
  8. ?>
  9. <a href="sample.php?delete_id=<?=$row['id']?>">delete</a>
  10. <?php } ?>

put your delete statement above...
(sample.php)
  1. //db connections..
  2.  
  3. if ($_GET['delete_id']!="")
  4. {
  5. //delete statement goes here....
  6. }
  7.  
  8. $result = mysql_query("SELECT commentid FROM comments")
  9. or die(mysql_error());
  10.  
  11. while($row = mysql_fetch_array( $result )) {
  12. ?>
  13. <a href="sample.php?delete_id=<?=$row['id']?>">delete</a>
  14. <?php } ?>
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #3
Jul 8th, 2008
Thankyou for your time ryan_vietnow
Passing it to the next page is what we are doing here too ....other than this method..

cant we simply run the query in the same page where the anchor tag is present instead of passing it over to next page?
Last edited by Kavitha Butchi; Jul 8th, 2008 at 12:24 am.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #4
Jul 8th, 2008
like
  1. //...database connections...
  2. <a href=mysql_query("DELETE FROM example WHERE age='15'")>delete</a>
something like that which works..where everything is coded in a single page rather than passing it over to the other page.
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #5
Jul 8th, 2008
Originally Posted by Kavitha Butchi View Post
like
  1. //...database connections...
  2. <a href=mysql_query("DELETE FROM example WHERE age='15'")>delete</a>
something like that which works..where everything is coded in a single page rather than passing it over to the other page.
AFAIK, Its not possible.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #6
Jul 8th, 2008
Hello kavitha try this...

  1.  
  2. <?
  3. /...database connections...
  4. if(!empty($_GET['delid'])){
  5. mysql_query("delete from category WHERE id='".$_GET['delid']."'");
  6. if(!empty($_GET['start']))
  7. {
  8. header("location:add_subcategory.php?msg=del&start=".$_GET['start']."");
  9. }else{
  10. header("location:samepage.php?msg=del");
  11. }
  12. }
  13. ?>
  14. //This is in your designing table...
  15. <td height="22" align="center" ><a href="javascript:del('<? echo $frow['id'];?>')">Delete</a> </td>
  16. //and this can be anyware in your page
  17.  
  18. <script language="javascript">
  19. var d = document.frmmngmall;
  20. function del(x)
  21. {
  22.  
  23. if(confirm("You want to delete this record"))
  24. {
  25. d.action="samepage.php?delid="+x;
  26. d.submit();
  27. }
  28.  
  29. return;
  30. }
  31. </script>


And your a href must be in form tag...

This is working finely...try this...

Thanks.
Shanti
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
1
  #7
Jul 8th, 2008
Hello kavitha try this...

  1.  
  2. <?
  3. /...database connections...
  4. if(!empty($_GET['delid'])){
  5. mysql_query("delete from category WHERE id='".$_GET['delid']."'");
  6.  
  7. header("location:samepage.php?msg=del");
  8.  
  9. }
  10. ?>
  11. //This is in your designing table...
  12. <td height="22" align="center" ><a href="javascript:del('<? echo $frow['id'];?>')">Delete</a> </td>
  13. //and this can be anyware in your page
  14.  
  15. <script language="javascript">
  16. var d = document.frmmngmall;
  17. function del(x)
  18. {
  19.  
  20. if(confirm("You want to delete this record"))
  21. {
  22. d.action="samepage.php?delid="+x;
  23. d.submit();
  24. }
  25.  
  26. return;
  27. }
  28. </script>
  29.  
  30.  
  31. <? /...database connections... if(!empty($_GET['delid'])){ mysql_query("delete from category WHERE id='".$_GET['delid']."'"); if(!empty($_GET['start'])) { header("location:add_subcategory.php?msg=del&start=".$_GET['start'].""); }else{ header("location:samepage.php?msg=del"); } } ?> //This is in your designing table... <td height="22" align="center" ><a href="javascript<b></b>:del('<? echo $frow['id'];?>')">Delete</a> </td> //and this can be anyware in your page <script language="javascript"> var d = document.frmmngmall; function del(x) { if(confirm("You want to delete this record")) { d.action="samepage.php?delid="+x; d.submit(); } return; } </script>

And your a href must be in form tag...

This is working finely...try this...

Thanks.
Shanti
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #8
Jul 8th, 2008
Thankyou shanthi chepuru.
I shall consider giving it a shot ...am little concerned as it involves Javascript.
I appreciate fr your time
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 67
Reputation: Kavitha Butchi is an unknown quantity at this point 
Solved Threads: 3
Kavitha Butchi Kavitha Butchi is offline Offline
Junior Poster in Training

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
0
  #9
Jul 8th, 2008
Originally Posted by nav33n View Post
AFAIK, Its not possible.
Hello nav33n,

thank you fr the response.

While googling fr this info I found out these broken strings..dont exactly if this is relevant or not.. thought I could ask it here...


You are not an employee of <br /> <b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user ...

So I thought there might be something like this function.mysql-query....

Please Let me know if nothing as such exists.


complete search result:
<br /> <b>Warning</b>: mysql_connect() [<a href='function.mysql ...
11) You are not an employee of <br /> <b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user ...
www.myrandomblogs.org/register.php - 25k - Cached - Similar pages - Note this

googled with search term as : <a href=function mysql(delete from
Kavitha
I Love My Indonesia.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: can we use mysql(DELETE...) query in the same page while having anchor tags?

 
1
  #10
Jul 8th, 2008
mysql_connect error is because the user gave wrong credentials to connect to the database.
Its not possible to call a php function or a mysql query with "onclick" event. As others have mentioned already, you can use ajax or pass the id of the record in the anchor tag and then do relevant operation.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC