wrathican Posted July 23, 2007 Share Posted July 23, 2007 i have never created a function before and i have read a few tutorials on them, but when i tried it, it didnt work. when you tell a function what variables to accept can you put '$_POST['value']?? because i am getting this error: Parse error: syntax error, unexpected '[', expecting ')' in F:\wamp\www\test\index.php on line 4 and here is my line 4: function function sendbooking($_POST['name'],$_POST['email'],$_POST['house'],$_POST['street'],$_POST['town'],$_POST['postcode'],$_POST['home'], $_POST['mobile'],$_POST['tour'],$_POST['price'],$_POST['day'],$_POST['month'],$_POST['year'],$_POST['experience'],$_POST['health']) Quote Link to comment Share on other sites More sharing options...
Guardian-Mage Posted July 23, 2007 Share Posted July 23, 2007 no you cannot. function sendbooking(name,email) { $name = $_POST['name']; $email = $_POST['email']; } etc. Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 23, 2007 Author Share Posted July 23, 2007 so i dont need the $_POST? just the name of the input the alue came from? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 23, 2007 Share Posted July 23, 2007 I think you might be a little mistaken with what you are doing with the functions. The names of the variables that you put inside the function definition are not necessarily the names of the variables that you wish to pass into the function. They are simply the names of the variables that will be used in the function. So, to pass variables from the POST array into a function, you would do something along the lines of: <?php function showname($name){ echo $name; } showname($_POST['name']); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 no you cannot. function sendbooking(name,email) { $name = $_POST['name']; $email = $_POST['email']; } etc. Much better of not using globals within functions, this would limit the function to only be able to work with $_POST. Something like.... <?php function foo($a,$b) { return "You passed $a and $b to the function"; } echo foo($_POST['name'],$_POST['email']); ?> is alot more usefull. Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 23, 2007 Author Share Posted July 23, 2007 ahh right, gotcha. thanks it seems to work at the moment but im having trouble with my mysql host so i cant test it unfortunately 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.