Parse error: syntax error, unexpected '{' error [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I know this error but i can't see. please help me. I can'T solve this error
my code:
if (isset($_POST['giris'])){
$papara = trim(strip_tags($_POST['paparagiris']));
if (empty($papara) {
echo "<center><b><font color='red'>Boş alan bırakmayınız!</font></b></center>";
}else{
$uyegiris = $baglanti->prepare("SELECT * FROM uyeler WHERE paparacuzdanno=? ");
$uyegiris->execute(array($papara));
if($uyegiris->rowCount()){
foreach ($uyegiris as $uyebilgi) {
$uyeIdsi = $uyebilgi['id'];
$cuzdanno = $uyebilgi['paparacuzdanno'];
}
$_SESSION["id"] = $uyeIdsi;
$_SESSION['cuzdanno'] = $cuzdanno;
}else{
echo "<center><font color='red'>Giriş sırasında bir hata oluştu.</font>/center>";
}
}
}

if (empty($papara) {
is missing a closing parenthesis ). Change it to
if (empty($papara)) {

Related

how can I solve a unexpected end of file error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I have some issue with my PHP file it's meant to put steps passed in a game on my database but when I try to submit my form it return me this error,
Parse error: syntax error, unexpected end of file in /***/**********/****/********/WWW/Page_Administrateur/InsertionEtape.php on line 31
here's my code:
<?php
include('../connexion.inc.php');
?>
<?php
if (isset($_POST["quantity"]) && $_POST["quantity"] != 0 && $_POST["quantity"] != "") {
$nbEtapes=$_POST['quantity'];
echo $nbEtapes;
for ($i=1; $i <= $nbEtapes; $i++) {
echo "etape".$i;
$DescriptionEtape=$_POST['NomEtape_'.$i];
$NomEtape=$_POST['DescriptionEtape_'.$i];
$req= "INSERT INTO `Etape` VALUES ('".$NomEtape."','".$DescriptionEtape."');";
try {
$dbh->query($req);
echo "Etape Ajouté";
} catch (\Exception $e) {
echo $e;
}
header('Refresh: 50; URL=FormulaireInsertion.php');
}
}else {
echo "aucune étapes ajouter car aucune étape n'a été entrée";
header('Refresh: 2; URL=FormulaireInsertion.php');
}
echo "done";
?>
how can I solve this ?
you are using header inside the loop try commenting
for ($i=1; $i <= $nbEtapes; $i++) {
echo "etape".$i;
$DescriptionEtape=$_POST['NomEtape_'.$i];
$NomEtape=$_POST['DescriptionEtape_'.$i];
$req= "INSERT INTO `Etape` VALUES ('".$NomEtape."','".$DescriptionEtape."');";
try {
$dbh->query($req);
echo "Etape Ajouté";
} catch (\Exception $e) {
echo $e;
}
//header('Refresh: 50; URL=FormulaireInsertion.php');
}

PHP syntax error, unexpected 'elseif' [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I get this error:
Parse error: syntax error, unexpected 'elseif' (T_ELSEIF) in C:\...\functions.php on line 6
This is the whole content of functions.php:
<?php
// prints the suitable string based on the chosen language
function lecho ($cs,$sk,$en) {
global $lang;
if ($lang=="cs") echo $cs;​
elseif ($lang=="​sk") echo $​sk;​
elseif ($lang=="​en") echo $​en;​​ // line 7
}
?>
What's wrong? This seams like such a basic thing!
You're just missing a space: it's else if, not elseif.
You need to use {'code here'} after an if/elseif/else statement. The correct way to go about this would be:
<?php
// prints the suitable string based on the chosen language
function lecho ($cs,$sk,$en) {
global $lang;
if ($lang=="cs") {
echo $cs;​
} elseif ($lang=="​sk") {
echo $​sk;​
} elseif ($lang=="​en") {
echo $​en;​​
}
}
?>
And it is simple. You just need to correct syntax for if/elseif
<?php
// prints the suitable string based on the chosen language
function lecho ($cs,$sk,$en) {
global $lang;
if ($lang=="cs")
{
echo $cs;​
}
elseif ($lang=="​sk")
{
echo $​sk;​
}
elseif ($lang=="​en")
{
echo $​en;​​ // line 7
}
}
?>

PHP Error when check if URL Query = equals to [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I get an error when I try to check if a query taken from the url equals something.
Error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')'
if (isset($_GET['lang'] == 'eng')) {
echo 'ENG';
}else if (isset($_GET['lang'] == 'alb')) {
echo 'ALB';
}else {
echo 'MKD';
}
Am I doing something wrong?
Thanks
You can not use == and isset to gether:
if (isset($_GET['lang']) && $_GET['lang']=='eng') {
echo 'ENG';
}
else if (isset($_GET['lang']) && $_GET['lang'] == 'alb') {
echo 'ALB';
}else {
echo 'MKD';
}

simple php if statement generates parse error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I've got this code
if ( !empty( $ImStoreCart->cart->items ) {
$count = $ImStoreCart->cart->items;
echo "Items in Basket: ". $count;
} else { echo "Your shopping basket is empty."; }
but I get this error: Parse error: syntax error, unexpected '{'
I've checked the code but cannot see why its failing to see the if statement that needs the {
Any ideas?
It was ")" missed in first line
if ( !empty( $ImStoreCart->cart->items )) {
$count = $ImStoreCart->cart->items;
echo "Items in Basket: ". $count;
} else { echo "Your shopping basket is empty."; }

PHP Parse error: syntax error, unexpected '}' [duplicate]

This question already has answers here:
Parse error: syntax error, unexpected '}' but can not find another [closed]
(3 answers)
Closed 10 years ago.
OK I'm returning to PHP after not using it for a couple of years and I'm trying to do a simple check of a $_POST variable.
I have:
if(isset($_POST['partydate'])) { $partydate = $_POST['partydate'] } else { $partydate = "No Date Selected" };
It's the only thing on that line but I keep getting the following when the page runs:
Parse error: syntax error, unexpected '}' in C:\xampp\htdocs....... on line 3
What is the obviously VERY simple thing I am overlooking here?!
One-liners are bad for code readability. If displayed better, your code becomes:
if (isset($_POST['partydate'])) {
$partydate = $_POST['partydate']
}
else {
$partydate = "No Date Selected"
}
;
So as you can see, you are missing semi-colons in your if and else blocks. Proper code is:
if (isset($_POST['partydate'])) {
$partydate = $_POST['partydate'];
}
else {
$partydate = "No Date Selected";
}
Use the ternary if if you really want to use a one-liner:
$partydate = isset($_POST['partydate']) ? $_POST['partydate'] : "No Date Selected";
Try this for size, with proper placement of ";"
if(isset($_POST['partydate'])) {
$partydate = $_POST['partydate'];
} else {
$partydate = "No Date Selected";
}
You have miss two
;
after the assignment of the string try this code:
if(isset($_POST['partydate'])) {
$partydate = $_POST['partydate'];
} else {
$partydate = "No Date Selected";
};

Categories