Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition problem router slow software sound spyware trojan usb video virus vista windows windows vista windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP Form and Function


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Firestone's Avatar
Computer Specs
Member with 32 posts.
 
Join Date: Dec 2006
Experience: Advanced
18-Feb-2007, 10:20 AM #1
PHP Form and Function
I'm trying to get it so that when a user clicks a button, it calls a PHP function. I though I could do it like with javascript (action = 'javascript:blank()') so I put the action as php:blank(), but it didn't work... anyone know how I could do this? Heres the code so you can see what I'm doing:

Code:
<?php
if (isset($_COOKIE["stat"]))
{
echo "Welcome member!";
echo "<form action = 'php:logOut()'>
<input type = 'submit' value = 'Log out' />
</form>";
}
else
{
echo "You must be logged in to do that!";
}

function logOut()
{
setcookie("stat", "", time()-3600);
echo "You are now logged out!";
}
?>
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
18-Feb-2007, 05:26 PM #2
<?php
function logOut() {
setcookie("stat", "", time()-3600);
echo "You are now logged out!";
}


if (isset($_COOKIE["stat"])) {

if ($_POST['submit']) {
logOut();

} else {
echo "Welcome member!";
echo "<form action = '" . $_SERVER['PHP_SELF'] . "' method='post'>
<input type = 'submit' name='submit' value = 'Log out' />
</form>";
}

} else {
echo "You must be logged in to do that!";
}

?>
Gibbs's Avatar
Senior Member with 638 posts.
 
Join Date: Feb 2005
Location: England
Experience: Intermediate
18-Feb-2007, 07:49 PM #3
You create a function with
PHP Code:
function myFunction() 

<function 
code

and you call it with
PHP Code:
myFunction(); 
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:00 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.