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';
}
Related
This question already has answers here:
php filter_var fails with zero on FILTER_VALIDATE_INT
(2 answers)
Closed 5 years ago.
I had issue about FILTER_VALIDATE_INT function when i put 0 as entry value it show 'error' instead of 'ok':
$delivery = 0;
if (filter_var($delivery,FILTER_VALIDATE_INT)) {
echo 'ok';
}else{
echo 'error';
}
Compare with false, because PHP consider zero returning as false
if (false !== filter_var($delivery,FILTER_VALIDATE_INT)) {
Check for strict type check it will work,
$delivery = 0;
if (filter_var($delivery,FILTER_VALIDATE_INT) !== false) {
echo 'ok';
}else{
echo 'error';
}
Demo
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)) {
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
}
}
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Error I'm getting is:
Parse error: syntax error, unexpected '{' in
xxx on line 272
Line 272 is:
<?php
if(htmlentities($shop['categorie']) == '1')
{ echo "Achtergronden"; }
elseif(htmlentities($shop['categorie']) == '2')
{ echo "Widgets"; }
elseif(htmlentities($shop['categorie']) == '3')
{ echo "Overig"; }
?>
Problem in else with condition
<?php
if(htmlentities($shop['categorie']) == '1') {
echo "Achtergronden";
} elseif(htmlentities($shop['categorie']) == '2') {
echo "Widgets"; }
// your version: else(htmlentities($shop['categorie']) == '3') {
// and correct one below
elseif(htmlentities($shop['categorie']) == '3') {
echo "Overig";
} ?>
You must use else ifrather than else in last condition
<?php
if(htmlentities($shop['categorie']) == '1')
{ echo "Achtergronden"; }
elseif(htmlentities($shop['categorie']) == '2')
{ echo "Widgets"; }
elseif(htmlentities($shop['categorie']) == '3')
{ echo "Overig"; }
?>
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."; }