# Another "if" php lil prob

**URL:** <https://forum.kirupa.com/t/another-if-php-lil-prob/11805>\
**Category:** programming\
**Created:** [January 22, 2003, 4:29pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805 "2003-01-22T16:29:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thediablo](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@thediablo](https://forum.kirupa.com/u/thediablo)\
**Post date:** [January 22, 2003, 4:29pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/1 "2003-01-22T16:29:24Z")

</div>

```php

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:31pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/2 "2003-01-22T16:31:15Z")

</div>

dont forget the “;”

the code should look like thsi:

```php

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:31pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/3 "2003-01-22T16:31:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:32pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/4 "2003-01-22T16:32:15Z")

</div>

o my god… the same prob again!?

lol!

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:32pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/5 "2003-01-22T16:32:56Z")

</div>

Oh! arrays:D

im new to PHP 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:34pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/6 "2003-01-22T16:34:12Z")

</div>

Well you are checking to see if a variable equals something, so wouldn’t it be…

```php

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

```

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:34pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/7 "2003-01-22T16:34:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:35pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/8 "2003-01-22T16:35:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:36pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/9 "2003-01-22T16:36:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:44pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/10 "2003-01-22T16:44:12Z")

</div>

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:

```php

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

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

$Quien = $Quien - 1;

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:45pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/11 "2003-01-22T16:45:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:46pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/12 "2003-01-22T16:46:39Z")

</div>

```php

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:48pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/13 "2003-01-22T16:48:46Z")

</div>

post the whole thing. it may help

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:51pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/14 "2003-01-22T16:51:01Z")

</div>

```php

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:52pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/15 "2003-01-22T16:52:07Z")

</div>

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 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:54pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/16 "2003-01-22T16:54:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 4:54pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/17 "2003-01-22T16:54:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 5:02pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/18 "2003-01-22T17:02:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 5:06pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/19 "2003-01-22T17:06:06Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 5:09pm UTC](https://forum.kirupa.com/t/another-if-php-lil-prob/11805/20 "2003-01-22T17:09:05Z")

</div>

Thanks for the help JUBBA!

:D:D:D

i see if i can figure it out.

:trout:

[Next page](https://forum.kirupa.com/t/another-if-php-lil-prob/11805.md?page=2)
