manix Posted June 29, 2011 Share Posted June 29, 2011 Why can't I use a function like that > function demote(){ $userprofile=$_GET['user']; mysql_query("UPDATE users SET adlevel=adlevel-1 WHERE username='$userprofile'"); } <input type='button' value='Demote' onclick='demote()'/> Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/ Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 you are trying to call a PHP function using javascript...this will cause unexpected results since PHP is Server-side and Javascript is Client-side Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236292 Share on other sites More sharing options...
manix Posted June 29, 2011 Author Share Posted June 29, 2011 It's actually like that <? function demote(){ $userprofile=$_GET['user']; mysql_query("UPDATE users SET adlevel=adlevel-1 WHERE username='$userprofile'"); } echo "some stuff before that <input type='button' value='Demote' onclick='demote()'/>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236296 Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 "onclick" is a javscript event and cannot be used with php. You will either need to convert your code to javascript or find a different method using PHP Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236306 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 29, 2011 Share Posted June 29, 2011 maybe this might work? <script> function demote(){ <?php $userprofile=$_GET['user']; mysql_query("UPDATE users SET adlevel=adlevel-1 WHERE username='$userprofile'"); ?> } </script> <body><input type='button' value='Demote' onclick='demote()'/></body> Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236308 Share on other sites More sharing options...
manix Posted June 29, 2011 Author Share Posted June 29, 2011 maybe this might work? <script> function demote(){ <?php $userprofile=$_GET['user']; mysql_query("UPDATE users SET adlevel=adlevel-1 WHERE username='$userprofile'"); ?> } </script> <body><input type='button' value='Demote' onclick='demote()'/></body> I liked the idea but it didn't work Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236312 Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 this is the last time I will write on this thread, since you do not want to listen. Using the javascript event onclick with a PHP function WILL NOT WORK Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236313 Share on other sites More sharing options...
manix Posted June 29, 2011 Author Share Posted June 29, 2011 I got it I was just replying to the fellow here.. Also I guess it's my fault but I forgot to mark it solved. cheers Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236314 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 29, 2011 Share Posted June 29, 2011 you can actually use ajax if you want. Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236316 Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 you can actually use ajax if you want. yes AJAX will work, since it does not try to call PHP using javascript...but instead sends the data to a PHP page to be processed using the XMLHttpResponse Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236317 Share on other sites More sharing options...
manix Posted June 29, 2011 Author Share Posted June 29, 2011 yeah but I have to learn how to use it first.. Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236320 Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 yes, you will, if you would like to learn AJAX, click on the "AJAX docs" link in my signature Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236321 Share on other sites More sharing options...
manix Posted June 29, 2011 Author Share Posted June 29, 2011 hey thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1236322 Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 1, 2011 Share Posted July 1, 2011 no prob. good luck. if you've got any prob, you can always come back here. but post it at the right forum section though Quote Link to comment https://forums.phpfreaks.com/topic/240701-custom-functions/#findComment-1237278 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.