HI i am beginner in PHP and really need some help

<head> 
<title>My Variables HTML Form</title> 
</head> 
<body> 
<h4>My HTML Form</h4> 
<?php
function display()
{
	echo "you called display function";
}

function profile()
{
	echo "you called Profile function";
}
?> 	
	

<form action="<?= $php_SELF ?>" method="POST">

        <input type="button" name="action" value="submitted" onClick="<? display() ?>" />
    <input type="button" name="submit" value="submit me!" onClick="<? profile() ?>" />

</form>



</body> 
</html>

it could not work at all. what i want is to call the function according to what i have clicked.
how to solve my problem?

thanks

Recommended Answers

All 2 Replies

Hello.

You have to check which button is closed :

<?php
      if(isset($_POST['action'])) { display(); }

      if (isset($_POST['submit'])) { profile(); }

?>

- Mitko Kostov

MitkOK is right with his code; but you have bigger problems before that:
- first of all, don't mix javascript function calls with php defined functions; get rid of those onClick="<? ....; those are javascript functions calls, but the functions you defined are php
- second: avoid using short open php tags (<?); use instead the long ones (<?php) that work on every server configuration;
Your code might work just fine without any correction (just with MitkOK addon code), but if you try to learn something here, than you should take the above into account.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.