vozzek Posted November 15, 2007 Share Posted November 15, 2007 Hi everyone, I'm trying to use the include function for the first time, and I can't get it to work. I'm sure it's something obvious, but could someone please tell me what's wrong? I have two files: test.php which calls cart_functions_test.php (both are in the same directory). test.php <?php include('cart_functions_test.php'); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test Page</title> </head> <body> <input name="Click Me" type="button" value="Click Me" onclick="danny()" /> </body> </html> cart_functions_test.php <?php function danny() { echo "I am here"; } ?> When I click the button, nothing happens. What am I missing? Thanks in advance. Sorry for the duplicate post... MERGED Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 15, 2007 Share Posted November 15, 2007 Your trying to use PHP like it's JavaScript. PHP is a server side language as JavaScript is a client side language. Your going to have to make your danny() function in JavaScript and call it. Quote Link to comment Share on other sites More sharing options...
vozzek Posted November 15, 2007 Author Share Posted November 15, 2007 Ah, okay. I wasn't sure if this was possible but was hoping it was. I know exactly what you mean. Thanks. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 15, 2007 Share Posted November 15, 2007 danny () is a PHP function, so you have to use <?php ?> in order to call it. You're trying to call it from HTML. Hopefully this will help you to resolve the issue. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 15, 2007 Share Posted November 15, 2007 if you really want to call a php function from html you'll have to use AJAX Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 15, 2007 Share Posted November 15, 2007 This topic has already been solved (It was double posted). Quote Link to comment Share on other sites More sharing options...
vozzek Posted November 15, 2007 Author Share Posted November 15, 2007 Okay, if I can use php to call a php function, can I do something like this? <form ACTION="view_cart.php" method="POST" name="addtocartform" id="addtocartform" onSubmit="return validateAddToCart(); <?php addToCart() ?>"> And if the validate fails, will it still execute the addToCart function? Quote Link to comment 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.