Blaze26 Blaze26 - 3 months ago 13
PHP Question

Weird WAMP localhost error

I'm trying to make a form that mails the information to me. Here's my code.

PHP:

$to = "mosescu_b@yahoo.com";
$subject = "Comanda de Magneti";

$name = $_POST["nume"] . $_POST["prenume"];
$email = $_POST["email"];
$phone = $_POST["telefon"];
$adress = $_POST["adresa"];

$message = <<<EMAIL

Comanda de Magneti de la $name

Adresa de E-mail este $email

Numarul de telefon este $phone

Adresa este $adress

EMAIL;

$header ="$email";

if($_POST){

mail($to, $subject, $message, $header);

$feedback = "Multumesc pentru comanda!"
}


HTML

<div class="form-group">
<form style="font-size: 1.25em; margin-left: 20px;" method="post" action="#">
<label for="nume">Nume<span style="color: red;">*</span></label> <input name="nume" id="nume" class="form-control" type="text" placeholder="Nume" title="nume">
<label for="prenume">Prenume<span style="color: red;">*</span></label> <input name="prenume" id="prenume" class="form-control" type="text" placeholder="Prenume" title="prenume">
<label for="email">E-Mail</label><span style="color: red;">*</span><input name="email" id="email" class="form-control" type="email" placeholder="E-Mail" title="email">
<label for="telefon">Numar Telefon</label><input name="telefon" id="telefon" class="form-control" type="number" placeholder="Numar Telefon" title="telefon">
<label for="adresa">Adresa</label><span style="color: red;">*</span><input name="adresa" id="adresa" class="form-control" type="text" placeholder="Strada/Numar/Localitate/Judet" title="adresa"> <br />
<input name="submit" class="btn-default" type="submit" value="Comanda!"></input>
</form>
<p id="feedback"><?php echo $feedback ?> </p>
</div>


The error I'm getting is :"Parse error: syntax error, unexpected '}' in C:\wamp64\www\Test\comanda-magneti.php on line 30"

Which is weird, since I'm very sure that the code wouldn't run properly without the curly bracket.

Answer

Change this:

$feedback = "Multumesc pentru comanda!"

to

$feedback = "Multumesc pentru comanda!";

You forgot to add semi colon. Semicolon is act is line terminator in PHP and of course you can skip it for last line. But in this case you have closing curly braces after that.

Also please move if($_POST) to top as you are checking for it below and accessing POST properties above.

So something like:

if(isset($_POST)){
    $to = "mosescu_b@yahoo.com";
    $subject = "Comanda de Magneti";

    $name = (isset($_POST["nume"]) ? $_POST["nume"] : '')  . isset($_POST["prenume"]) ? $_POST["prenume"] : '' ;
    $email = isset($_POST["email"]) ? $_POST["email"];
    $phone = isset($_POST["telefon"]) ? $_POST["telefon"] : '';
    $adress = isset($_POST["adresa"]) ? $_POST["adresa"] : '';

    $message = <<<EMAIL

Comanda de Magneti de la $name

Adresa de E-mail este $email    

Numarul de telefon este $phone

Adresa este $adress

EMAIL;

    $header ="$email";

    mail($to, $subject, $message, $header);

    $feedback = "Multumesc pentru comanda!"
}  

Also if possible do necessary check for POST variable for required fields.

Comments