Jump to content

[SOLVED] Problem with array and If statement


rilana

Recommended Posts

Hy guyes I am having a Problem with an output of any array. Could you please help me?

I am having an Info Page with the following information that works.

 

 <tr> 
    <td colspan="3" valign=top> <span class="inhalt"> 
     smartpersonal gmbh<br><?=$a[sig]?><br>Churerstrasse 20<br>8808 Pfäffikon SZ<br>
Tel. 055 417 30 10<br>Fax 055 417 30 19<br><br> </span>
    <tr> 
      <td height="41" colspan="2" align=center valign="bottom"> 
      <form action=http://www.smartpersonal.ch/contact.php method=post>
      <input type=hidden name=job_id value=<?=$a[job_id]?>>
      <input type=hidden name=sig value=<?=$a[sig]?>>
        <input type=submit name=friend value="Bewerbung über unser Kontaktformular">   </form>      </td>
     
      <td align=center valign="bottom"><form action=Send.php method=post>
        <input type=hidden name=job_id value=<?=$a[job_id]?>>
        <input type=submit name=friend value="an einen Freund senden">  
      </form></td>
    </tr>

 

<input type=hidden name=sig value=<?=$a[sig]?>> Is the Person who wrote the Info and the output of this is someting like Rilana Martinato

but I am sendeing this Info to a PHP Contact Page which is not connected to the database with the above input hidden..... the Problem now is that when I echo $sig in my contact page it want give me Rilana Martinato it will only output Rilana so basicely it want output the spaces it stops after the first word. What do I need to do now? Is there an easy way? Like another command? When I echo <?=$a[sig]?> nothing works at all, but if I output only $sig, it will only show the first word. Please help me, I would realy aprechiate it!

 

Thanks a lot! Rilana

Oh no, I still have a problem!

 

echo "$sig";

if ($sig == "Herr Colin Rhyner") {
    $myemail= "[email protected]";
} elseif ($sig == "Frau Loan Do") {
    $myemail= "[email protected]";
} elseif ($sig == "Frau Manuela Jau") {
    $myemail= "[email protected]";	
} else {
    $myemail= "[email protected]";
}

 

i tryed everything, with "" without "" wich echo without echo... If I put sig = "" on top and then start the if funktion it works, but that's not what I need. What do I need to put bevor the if statement so it will take the sig value? Please help.

<?php
if  (isset($_POST['sig']) )            // if form submitted, process data
{
    $sig = $_POST['sig'] ;             // get hidden form value
    
    echo $sig, ' ', myemail($sig);                // get the email address
}


function myemail($sig)
{
    $emails = array (
            'Herr Colin Rhyner' => '[email protected]',
            'Frau Loan Do'      => '[email protected]',
            'Frau Manuela Jau'  => '[email protected]'            
        );
    return isset($emails[$sig]) ? $emails[$sig] : '[email protected]';
}
?>

                    <?php
                    //
                    // provide sample form data
                    // - for test only
                    //
                        $a = array ('sig' => "Herr Colin Rhyner");        
                    ?>

<form method='post'>
<input type="hidden" name="sig" value="<?=$a['sig']?>">
<input type="submit" name="btnSub" value="Submit">
</form>

I getting an array send to my contact form. and If I echo $sig it shows that ist's there. But the following if statement does not work. Do I need to say anything bevor I start the if statement? I tryed everything. with and without "" with and without echo... Please help.

 


echo "$sig";

if ($sig == "Herr Colin Rhyner") {
    $myemail= "[email protected]";
} elseif ($sig == "Frau Loan Do") {
    $myemail= "[email protected]";
} elseif ($sig == "Frau Manuela Jau") {
    $myemail= "[email protected]";	
} else {
    $myemail= "[email protected]";
}

<?php

print_r($sig);

if ($sig == "Herr Colin Rhyner") {
    $myemail = "[email protected]";
} elseif ($sig == "Frau Loan Do") {
    $myemail = "[email protected]";
} elseif ($sig == "Frau Manuela Jau") {
    $myemail = "[email protected]";	
} else {
    $myemail = "[email protected]";
}

?>

 

^ What is the output of that?

thanks for your reply the output is correct but it still does not help if I put it in front of the if statement.

It ignores it and allways sends the form to else. Do you have any other sugestions?

 

What is the output!? I need to see it to make sure you're calling the variables properly.

OK sorry guyes, I thaught since I have a new problem it would be better to open a new post and put the old one on solved... sorry! I am still trying for Barand sucestion. But it doesnt seem to work... it causes an error. I will be back in a fiew minutes with more input on that... thanks for helping.

This does not work eighter.

The output is nothing and the form gives an error when sending.

Please do you have any other solutions?

 

I dont understand if  (isset($_POST['sig']) )            // if form submitted, process data

Does that simply ask if the previous form has send the array?

 

<?php
if  (isset($_POST['sig']) )            // if form submitted, process data
{
    $sig = $_POST['sig'] ;             // get hidden form value
    
    echo $sig, ' ', myemail($sig);                // get the email address
}


function myemail($sig)
{
    $emails = array (
            'Herr Colin Rhyner' => '[email protected]',
            'Frau Loan Do'      => '[email protected]',
            'Frau Manuela Jau'  => '[email protected]'            
        );
    return isset($emails[$sig]) ? $emails[$sig] : '[email protected]';
}
?>

                    <?php
                    //
                    // provide sample form data
                    // - for test only
                    //
                        $a = array ('sig' => "Herr Colin Rhyner");        
                    ?>

 

I dont understand if  (isset($_POST['sig']) )            // if form submitted, process data

Does that simply ask if the previous form has send the array?

 

 

Yes.

 

Please define "doesn't work". (It was working when it left the shop)

 

What error does the form give?

 

One thing to try. Put this code in your form processing script so you can see what is being sent

echo '<pre>', print_r($_POST, 1), '</pre>';

Ok I am getting an error e-mail to the right e-mail! I mean the one it requested in the if statement...

The error is the following...

A message that you sent contained no recipient addresses, and therefore no
delivery could be attempted.

------ This is a copy of your message, including all the headers. ------

To: 
Subject: Kontaktformular
X-PHP-Script: www.smartpersonal.ch/contact.php for 91.138.3.198
From: Rilana <[email protected]>
Reply-To: Rilana <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="6a9b7f85ad34d1b71c4b1167e5620441"
X-Sender: 91.138.3.198
X-Mailer: PHP/5.2.5
X-Priority: 3
Return-Path: <[email protected]>
Message-Id: <[email protected]>
Date: Sat, 19 Apr 2008 12:46:16 +0200

This is a multi-part message in MIME format.


--6a9b7f85ad34d1b71c4b1167e5620441
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

job_id: 356
Firma: 
Anrede: Herr
Name: Rilana
Adresse: 
PLZ: Ort: 
Telefon: 0764330662
ddd
--6a9b7f85ad34d1b71c4b1167e5620441--

 

And this is the output with echo '<pre>', print_r($_POST, 1), '</pre>';

 

Array
(
    [job_id] => 356
    [yourname] => Rilana
    [firma] => 
    [anrede] => Herr
    [adresse] => 
    [plz] => 
    [ort] => 
    [telefon] => 0764330662
    [youremail] => [email protected]
    [emailsubject] => 
    [yourmessage] => ddd
    [submit] => true
)

 

So your code seems to work, but I guess there is some mailserver Problem that comes with it for some reaseon.

oh this is wierd, why does it get send to the write reciever?

 

anyway it is a pretty complex form because it didn't know how to do an attachement with a form thats why I took this form from a tutorial. it has difined variables for headers and message.

 

//Headers

	$headers="From: ".$yourname." <".$youremail.">\n";
	$headers.="Reply-To: ".$yourname." <".$youremail.">\n";
	$headers.="MIME-Version: 1.0\n";
	$headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
	$headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
	$headers.="X-Mailer: PHP/".phpversion()."\n";
	$headers.="X-Priority: ".$priority."\n"; 
	$headers.="Return-Path: <".$youremail.">\n";
	$headers.="This is a multi-part message in MIME format.\n";

	//Message

	$message = "--".$boundary."\n";
	$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
	$message.="Content-Transfer-Encoding: quoted-printable\n";
	$message.="\n";
	$message.="job_id: $job_id";
	$message.="\n";
	$message.="Firma: $firma";
	$message.="\n";
	$message.="Anrede: $anrede";
	$message.="\n";
	$message.="Name: $yourname";
	$message.="\n";
	$message.="Adresse: $adresse";
	$message.="\n";
	$message.="PLZ: $plz";
	$message.="Ort: $ort";
	$message.="\n";
	$message.="Telefon: $telefon";
	$message.="\n";
	$message.="$yourmessage";
	$message.="\n";

 

do I need to ad $sig there?

Now I did add the $sig variable. The output looks like that now

 

Array
(
    [job_id] => 356
    [$sig] => Frau Loan Do
    [yourname] => Rilana
    [firma] => 
    [anrede] => Herr
    [adresse] => 
    [plz] => 
    [ort] => 
    [telefon] => 0764330662
    [youremail] => [email protected]
    [emailsubject] => 
    [yourmessage] => t
    [submit] => true
)

 

$sig is there but the error still exists.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.