943,716 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4160
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 7th, 2008
0

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

Expand Post »
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:-
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 8th, 2008
1

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

php Syntax (Toggle Plain Text)
  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)
php Syntax (Toggle Plain Text)
  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)
php Syntax (Toggle Plain Text)
  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 } ?>
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Jul 8th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 8th, 2008
0

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

like
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 8th, 2008
0

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

like
php Syntax (Toggle Plain Text)
  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.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 8th, 2008
0

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

Hello kavitha try this...

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 8th, 2008
1

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

Hello kavitha try this...

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 8th, 2008
0

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

Thankyou shanthi chepuru.
I shall consider giving it a shot ...am little concerned as it involves Javascript.
I appreciate fr your time
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 8th, 2008
0

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

Click to Expand / Collapse  Quote originally posted by nav33n ...
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
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 8th, 2008
1

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

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.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Not all rows are being displayed in mysql_fetch_row function
Next Thread in PHP Forum Timeline: heredoc Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC