Another "if" php lil prob


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?

dont forget the “;”

the code should look like thsi:


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

and you could probably use an array to make it a little neater.

o my god… the same prob again!?

lol!

lemme check… thanks jubba gonna put a note on my monitor “dont forget the ; !!!”

Oh! arrays:D

im new to PHP :stuck_out_tongue:

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.

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 { "

I think it will work either way. The more correct way would be ==

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 =.

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]";
?>

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


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?

post the whole thing. it may help


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 {
?>

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 :stuck_out_tongue:

You used == on “1” and “3”, but not on “2”

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.

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 :stuck_out_tongue: var comes from…

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 :slight_smile:

Thanks for the help JUBBA!

:D:D:D

i see if i can figure it out.

:trout: