...

View Full Version : proble with or die in contact script



Adbem
02-03-2010, 03:41 PM
That is the php part of my contact script

<?php

$alertall = "you need to fill in all fields";

if ($_POST['name'] == "")
echo"<? $alertall ?>";

if ($_POST['email'] == "")
echo"<? $alertall ?>";

if ($_POST['title'] == "")
echo"<? $alertall ?>";

if ($_POST['text'] == "")
echo"<? $alertall ?>";

else {
mail ('kontakt@mywebsite.com', '$title', '$text');
echo"it was send correctly, go back on <a href=\"http://www.mywebsite.com\">main page</a><br /> or to <a href=\"http://www.mywebsite.com\">cobntact formular</a>";
} or die { "Impossible to send a formular"; }


?>

The problem is that it shows an error
T_LOGICAL_OR? What can be wrong?

angst
02-03-2010, 03:47 PM
try this;




$alertall = "you need to fill in all fields";

if ($_POST['name'] == "") echo $alertall;

if ($_POST['email'] == "") echo $alertall;

if ($_POST['title'] == "") echo $alertall;

if ($_POST['text'] == "") echo $alertall;

if($alertall <> ""){
echo $alertall;
} else {
mail ('kontakt@mywebsite.com', '$title', '$text') or die ("Impossible to send a formular");
}

abduraooft
02-03-2010, 03:54 PM
The problem is that it shows an error
T_LOGICAL_OR
? What can be wrong? What do you expect for that or die() part?

tomws
02-03-2010, 03:57 PM
I think the curly braces are out of whack in that, angst.

@Abdem: else..or die() won't work. An else is the final condition of an if/else structure, so you can't OR anything with it. Perhaps you mean to use an elseif instead?

Adbem
02-03-2010, 04:00 PM
If somebody try to contact with using that formular and it is impossible to show him a message that it's impossible

@up I didn't see your post

angst
02-03-2010, 04:01 PM
yah your right, I missed one, but also noticed some more issues with his code. updated*

JAY6390
02-03-2010, 04:15 PM
I'm not sure why you want to echo out the error message every time there's an error. If no fields are set you are going to get the error message sent 4 times. Try something like this instead

$fields = exlpode(',', 'name,email,title,text');
$error = false;

foreach($fields as &$v) {
if(!isset($_POST[$v]) || trim($_POST[$v] == '')){
$error = true;
break;
}else{
$v = trim($v);
}
}

if($error) {
die('You need to fill in all fields');
}else{
if(!mail('kontact@mywebsite.com', $title, $text)) {
die('Impossible to send a formular');
}else{
echo 'it was send correctly, go back on <a href="http://www.mywebsite.com">main page</a><br /> or to <a href="http://www.mywebsite.com">cobntact formular</a>';
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum