Grego Posted June 21, 2007 Share Posted June 21, 2007 I have an <a> tag and I want to call a PHP function (defined at the top of the page) in it. I tried using "OnClick='del_image(4)'" but that didn't seem to work. Is there a way of doing this? Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/ Share on other sites More sharing options...
pocobueno1388 Posted June 21, 2007 Share Posted June 21, 2007 From the sound of it, this is a javascript issue. So if it is, this would probably get better answers over there. Some code would also be helpful. Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/#findComment-279456 Share on other sites More sharing options...
Grego Posted June 21, 2007 Author Share Posted June 21, 2007 No. Sorry. It's PHP. The PHP function is: function del_image($arg1) { mysql_query("DELETE FROM images WHERE ImageID='$arg1'"); } And the call is: <a href='user_index.php?qry=3' OnClick='del_image(4)'>[Delete Image]</a> Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/#findComment-279457 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Share Posted June 21, 2007 OnClick is used in javascript so I think you're going to have to add some Javascript code in there... Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/#findComment-279462 Share on other sites More sharing options...
Grego Posted June 21, 2007 Author Share Posted June 21, 2007 Can I call the PHP function in JavaScript? Or is there another way to do it? With or without OnClick Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/#findComment-279464 Share on other sites More sharing options...
Lumio Posted June 21, 2007 Share Posted June 21, 2007 No! PHP is a serverbased language and Javascript is a browserbased language. So the only way is to use AJAX or doing it something like that. Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/#findComment-279467 Share on other sites More sharing options...
suma237 Posted June 22, 2007 Share Posted June 22, 2007 Try this... <?php $id = $_POST['id']; $delete = mysql_query("DELETE FROM `projects` WHERE id='$id'") or die(mysql_error()); header('Location: http://somesite.com/project.php'); <a href="main.php?id=<?=$row['id']?>" onclick="alert('Do you want to delete')">Delete</a> ?> Link to comment https://forums.phpfreaks.com/topic/56587-call-php-function-in/#findComment-279998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.