Re: If statement being ignored by PHP
| From: | Mike Gifford | Date: | Fri, 30 Jun 2000 16:48:29 +0000 |
| Subject: | Re: If statement being ignored by PHP | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4053@lists.php.net to get a copy of this message | ||
Hi Jurian,
Your help was great, except that I'm not quite out of the woods yet. I
think I have the if statments worked out. Except now I have a problem
posting a form within a code.
I would like the form that I've posted in Section A to stay on the same
page and to implement the code I have set up in section B.
Unfortunately, when I submit the form, it completely refreshes the whole
page and removes the variables that were posted there previously. Would
I have to hide the previously posted variables in this form to to send
the mail with the variables $remail $sender semail & $message already
defined?
If this is a bit confusing the pages that this is being implemented in
are here:
http://www.openconcept.on.ca/cards/send.phtml
http://www.openconcept.on.ca/cards/send.php3
I've included the whole send.php3 file to the bottom and have included
the specific section of the text is here:
if ($semail != "") {
// Section A
echo "<form method=\"GET\" action=\"send.php3\">";
echo "<input type=\"radio\" value=\"yes\"
NAME=\"epost\">Yes, please
send my card!";
echo "<input type=\"radio\" value=\"no\" NAME=\"epost\">No,
I will try
again.";
echo "<input type=\"submit\"
value=\"Submit\"></form><br>";
// Section B
if ($epost == "yes") {
mail("$recipient <$remail>", "$sender has sent you a card",
$message,"From: $semail \nReply-To: $semail\nX-Mailer: PHP3");
echo "Your card number $idnumber has been sent to $recipient.<p>\n";
}
elseif ($epost == "no") { echo "<strong>Please rewrite your card and try
again.</strong><p>\n"; }
elseif ($epost == "") { echo "<strong>You have not yet sent the
card.</strong><p>\n"; }
else { echo ""; }
}
else { echo "<strong>This card was NOT sent because the sender's email
address was not provided!</strong><p>\n"; }
WHOLE SEND.PHP3 FILE
<?php
// HTML Title Variable
$htitle = "Janni's Cards: ";
// Web Page Title Variable
$dtitle = "Send a Card";
// Date Changed Variables
$date = Date("d/M/y", getLastMod());
// Include Title Bar and Side Bar
include ("head.phtml");
?>
<?php
// Text file for saving cards
$cardfile="cardfile.txt";
// Counter Script
$free=0;
$empty="empty\n";
$oldcards = file($cardfile);
$total = count($oldcards);
for($i = 0 ; $i < count($oldcards) ; $i++) {
if($array[$i] == $empty) {
$free=$i;
}
}
if($free=="0"){
if($oldcards==$empty){
$free=0;
}
else {
$free=$total;
}
}
// Place existing cards into an array.
$fd = fopen("$cardfile", "r");
$oldcards = ""; // Leave this blank
while ($buffer = fgets($fd, 4096)) {
$oldcards .= $buffer;
}
fclose($fd);
// What is written to the Text File
$newcard = $free+1 . ":" . $picture . ":" . $remail . ":" . $recipient
.
":" . $semail . ":" . $sender . ":" . $message . "\n";
$allcards = $oldcards . $newcard;
$idnumber=$free+1;
// If the recipient's email isn't empty, append to file
if ($remail!="") {
$cartFile = fopen("$cardfile","w");
fwrite($cartFile,$allcards);
fclose($cartFile);
// Preview Message
echo "<table BORDER=0 WIDTH=\"100%\">\n<tr>\n<td ALIGN=CENTER
VALIGN=TOP>\n<IMG src=\"graphics/$picture\">\n</td>\n ";
echo "<td VALIGN=TOP>\n<table BORDER=0 CELLSPACING=0 CELLPADDING=0
COLS=2
WIDTH=\"100%\">\n<tr>\n<td>\n<b>To:</b>\n</td>\n<td>\n<a
href=\"mailto:$remail\">";
echo "$recipient</a>\n</td>\n</tr>\n";
echo "<tr>\n<td>\n<b>From:</b></td>\n<td>\n<a
href=\"mailto:$semail\">";
echo "$sender</a>\n</td>\n</tr>\n</table>\n";
echo
"<B>Message:</B><BR>$message</td>\n</td>\n</tr>\n</table>\n";
// Message to be included in email
$message = "To pick up your card, visit
http://www.openconcept.on.ca/cards/receive.phtml
and enter number $idnumber
or
click on
http://www.openconcept.on.ca/cards/receive.php3?viewcard=$idnumber";
// If senders email isn't blank, send card.
// if (exist($semail)):
$epost="";
if ($semail != "") {
echo "<form method=\"GET\" action=\"send.php3\">";
echo "<input type=\"radio\" value=\"yes\"
NAME=\"epost\">Yes, please
send my card!";
echo "<input type=\"radio\" value=\"no\" NAME=\"epost\">No,
I will try
again.";
echo "<input type=\"submit\"
value=\"Submit\"></form><br>";
if ($epost == "yes") {
mail("$recipient <$remail>", "$sender has sent you a card",
$message,"From: $semail \nReply-To: $semail\nX-Mailer: PHP3");
echo "Your card number $idnumber has been sent to $recipient.<p>\n";
}
elseif ($epost == "no") { echo "<strong>Please rewrite your card and try
again.</strong><p>\n"; }
elseif ($epost == "") { echo "<strong>You have not yet sent the
card.</strong><p>\n"; }
else { echo ""; }
}
else { echo "<strong>This card was NOT sent because the sender's email
address was not provided!</strong><p>\n"; }
}
else { echo "<strong>A preview was NOT provided because the recipients's
email address was not provided!</strong><p>\n"; }
echo "Would you like to <a href=\"send.phtml\">send another
card</a>";
?>
<?php
// Include Footer
include ("foot.phtml");
?>
--
Mike A. Gifford OpenConcept Consulting
Mike@OpenConcept.On.Ca Http://www.OpenConcept.On.Ca
Web Design, Hosting, Graphic Design & Site Promotion
Featured Site --> Http://WTOAction.Org