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
 //db connections..

$result = mysql_query("SELECT commentid FROM comments") 
or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
 	<a href="<?php //delete this row ?>">delete</a>
<?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.

<?php
 //db connections..

$result = mysql_query("SELECT commentid FROM comments") 
or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
 	<a href="<?php //delete this row ?>">delete</a>
<?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
 //db connections..

$result = mysql_query("SELECT commentid FROM comments") 
or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
 	<a href="sample.php?delete_id=<?=$row['id']?>">delete</a>
<?php } ?>

put your delete statement above...
(sample.php)

//db connections..

if ($_GET['delete_id']!="")
{
//delete statement goes here....
}

$result = mysql_query("SELECT commentid FROM comments") 
or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
 	<a href="sample.php?delete_id=<?=$row['id']?>">delete</a>
<?php } ?>
Comments
thank you fr your time

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?

like

//...database connections...
<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.

like

//...database connections...
<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.

Hello kavitha try this...

<?
/...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: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

Hello kavitha try this...

<?
/...database connections...
if(!empty($_GET['delid'])){  
	mysql_query("delete from category WHERE id='".$_GET['delid']."'");
	
	header("location:samepage.php?msg=del");
	
}
?>
//This is in your designing table...
 <td height="22" align="center" ><a href="javascript: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>
 

<? /...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

Thankyou shanthi chepuru.
I shall consider giving it a shot ...am little concerned as it involves Javascript.
I appreciate fr your time :)

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() [[B][U]<a href='function.mysql-connect'>function.mysql-connect</a>[/U][/B]]: Access denied for user ...

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

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

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.

Comments
ok, thank you fr ur time.
This question has already been answered. Start a new discussion instead.