Jump to content

[SOLVED] function help


wrathican

Recommended Posts

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'])

Link to comment
Share on other sites

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']);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.