PDA

View Full Version : Another "if" php lil prob



thediablo
January 22nd, 2003, 11:29 AM
if ($Quien = "2") { $Quien = "Webmaster" }
if ($Quien = "1") { $Quien = "Publicidad" }
if ($Quien = "3") { $Quien = "Otro" }



Is that code correct?

the numbers and the vars. are getted from a html form (a 3 option combo box)

but im gettin gthis error...

Parse error: parse error, unexpected '}' in <URL> on line 38

Any ideas?

Jubba
January 22nd, 2003, 11:31 AM
dont forget the ";"

the code should look like thsi:



if ($Quien = "2")
{
$Quien = "Webmaster";
}
if ($Quien = "1")
{
$Quien = "Publicidad";
}
if ($Quien = "3")
{
$Quien = "Otro";
}

Jubba
January 22nd, 2003, 11:31 AM
and you could probably use an array to make it a little neater.

thediablo
January 22nd, 2003, 11:32 AM
o my god... the same prob again!?

lol!

lemme check... thanks jubba gonna put a note on my monitor "dont forget the ; !!!"

thediablo
January 22nd, 2003, 11:32 AM
Oh! arrays:D

im new to PHP :P

lostinbeta
January 22nd, 2003, 11:34 AM
Well you are checking to see if a variable equals something, so wouldn't it be...



if ($Quien == "2") {
$Quien = "Webmaster";
}
if ($Quien == "1") {
$Quien = "Publicidad";
}
if ($Quien == "3") {
$Quien = "Otro";
}



Because == checks to see if that variable equals something.

Jubba
January 22nd, 2003, 11:34 AM
yeah, everything needs to have a ;

The only things that don't are 'if statements, loops of some kind (while, for, do) or lines that only have a } or { "

Jubba
January 22nd, 2003, 11:35 AM
I think it will work either way. The more correct way would be ==

lostinbeta
January 22nd, 2003, 11:36 AM
Oh... I know in Flash and Javascript = doesn't work, you need == , so I just do it in PHP that way naturally, never tried with one =.

Jubba
January 22nd, 2003, 11:44 AM
actually, now that you mention it, neither have I. Everything I have ever used PHP for has been returning a Bealoon value, TRUE or FALSE. So I always use !=

Oh, and for the array, try this:


<?
$Quien = $_POST['Quien'];

$myArray = array ("Webmaster", "Publicidad", "Otro");

$Quien = $Quien - 1;

print "$myArray[$Quien]";
?>

Jubba
January 22nd, 2003, 11:45 AM
Because Arrays are ZERO based, you have to subract one from the variable Quien, in order for the array to work. Instead of 1,2,3 the values for the array are 0,1,2

thediablo
January 22nd, 2003, 11:46 AM
if ($Quien == "Webmaster") {
mail("chidos@hotmail.com","$subject","$message","From: $Name <$Email>");
}
if ($Quien == "Publicidad") {
mail($toemail,"$subject","$message","From: $Name <$Email>");
}
if ($Quien == "Otro") {
mail($toemail,"$subject","$message","From: $Name <$Email>");
}



Now the other code seems to be working now (the if)

but when it gets here,no matter which option is selected it always sends the email to Webmaster.. you know what could causing it?

To get here it goes tru a check if the fields are correct if the email is correct... etc...

should i put all the code?

Jubba
January 22nd, 2003, 11:48 AM
post the whole thing. it may help

thediablo
January 22nd, 2003, 11:51 AM
if ($Quien = "2")
{
$Quien = "Webmaster";
}
if ($Quien == "1")
{
$Quien = "Publicidad";
}
if ($Quien == "3")
{
$Quien = "Otro";
}

if($submitform) {

// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Falta $dcheck[$check]<br>";
}
}

// check email address
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
$error .= "Email Invalido<br>";}

// display errors
if($error) {
?>

<b>Error</b><br>
<?php echo $error; ?><br>
<a href="#" onClick="history.go(-1)">Intenta de nuevo</a>

<?php
}
else
{

$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;

// format message
$message = "Mensaje desde Contactanos:

E-Mail Dirigido a $Quien

Nombre: $Name
Email: $Email
Telefono: $Tel

Mensaje: $Comments

-----------------------------

Browser: $browser
User IP: $ip";

// send mail and print success message
if ($Quien == "Webmaster") {
mail("chidos@hotmail.com","$subject","$message","From: $Name <$Email>");
}
if ($Quien == "Publicidad") {
mail($toemail,"$subject","$message","From: $Name <$Email>");
}
if ($Quien == "Otro") {
mail($toemail,"$subject","$message","From: $Name <$Email>");
}
//hurrah i think it stands
if($hurrah) {
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
echo "$thanks";
}
}
}
else {
?>

thediablo
January 22nd, 2003, 11:52 AM
theres more code but its for the FORM and some vars that you set on top of the file...

you need that to?

if so, ill attach the file :P

lostinbeta
January 22nd, 2003, 11:54 AM
You used == on "1" and "3", but not on "2"

Jubba
January 22nd, 2003, 11:54 AM
nah, in your first if statement, change the = to ==. I think it may be causing the problem. I think the one = is setting the variable to 2 and therefore it always will send to webmaster.

thediablo
January 22nd, 2003, 12:02 PM
well the if for webmaster is working...

but when i try and select another option from the box, it simply dosent send the email.

also... i think the Autoresponse at the bottom of that dosent seem to work..

and i dont where the $hurrah :P var comes from...

Jubba
January 22nd, 2003, 12:06 PM
did you change the = to == tho? that could be causing the whole problem...

Also, I have no idea what that is... if you don't need the autoresponce thing I would take it out...

I have to go to class now.... good luck with everything :)

thediablo
January 22nd, 2003, 12:09 PM
Thanks for the help JUBBA!

:D:D:D

i see if i can figure it out.

:trout:

kalimqvka
January 22nd, 2003, 11:16 PM
Y don't U try the if...elseif statement:

if ($Quien = "2") {
$Quien = "Webmaster";
} elseif ($Quien = "1") {
$Quien = "Publicidad";
} elseif ($Quien = "3") {
$Quien = "Otro";
} else {$Quien="";}