Explain-me please

Hi ppl I started todey learning php alone, i started to making something and the result it’s not ok.

[php]<?php
function calcaro()
{
define(“L”,5);
define(“H”,5);
$aro = array( “largura” => “L”, “altura”=>“H”);
echo "o valor e ". (($aro[largura])*2+($aro[altura])*2);
}
calcaro();

?>[/php]

The result of this shouldn’t be 25? not 0 rigth? What’s wrong?
Thanks for your help

Because you defined L and H as named constants, you need to use them without any quotes. You need to correct this line in your code:
[php]$aro = array( “largura” => L, “altura”=>H);[/php]

and result is actually 20, not 25 :slight_smile:

(Another newbie…)
I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code below resolves is a parse error at the last “if”-line.
Scenario:

I have 3 fields: arrival, departure and no of persons (pax) to check.
When arrival (date_start) is entered and departure (date_end) is entered, there should be an entry in the field “pax” as well. If not, there should be a message: “please tell us the number of persons in your group”. The code is currently:

arrival, departure and comments empty (works fine):

} if(empty($data_start) && empty($data_end) && empty($comment)){
exit(“You have not specified any details to submit to us.”); }

arrival, departure given, but pax empty (resolves in parse error):

if(!isset($data_start) && if(!isset($data_end)) && if(empty($pax)){
exit(“Please tell us the number of persons in your group.”); }

Error:
Parse error: syntax error, unexpected T_IF in /home/xxxx/xxxx (last line).

Can someone please check and tell me what’s wrong with the last string ? Thanks to anyone for any hint.

Problem above solved. Thank you.

Thank you all:)

Another scenario:
I have already an online booking form. The Form works fine now and I would like to add on one more
issue, but the code ignores what I want to check. I have 4 fields: arrival, departure. no. of persons and comments to check.

Scenario 1:

All field mentioned above are emtpty: Workes fine and message appears: “You have not provided any booking details”.

Scenario 2:

If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field “comment”, or in the field “pax”. If not, there should be a message: “You have not provided sufficient booking details”.

INSTEAD: The booking request is sent, which should not be the case.

The code is currently:

	# all fields empty : arrival, departure, pax and comments - error

if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){
exit(“You have not specified any booking details to submit to us.

Please use your browser to go back to the form.

If you experience problems with this Form, please e-mail us”);
exit;
}
#If arrival and departure date is entered, there should be at least an entry

either in the field “comment”, or in the field “pax”.

if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){
exit(“You have not provided sufficient booking details.

Please use your browser to go back to the form.

If you experience problems with this Form, please e-mail us”);
exit;
}

The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php

Can someone please check and tell me what’s wrong with the code ? Thanks to anyone for any hint.

OK - forget it !
This forum is obviously sleeping all day long, or nobody knows any answer.
My problem is solved otherwise

bye

Sponsor our Newsletter | Privacy Policy | Terms of Service