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"; }
?>
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I'm having trouble with this error message:
WEIRD Parse error: syntax error, unexpected 'if' (T_IF) ERROR LINE 11
And the code is this:
foreach($admins as $admin){
echo "
<tbody>
<tr>
<td>".++$menuCounter."</td>
<td><a href='adminprofile.php?user_name=".$admin['user_name']."'>".$admin['user_name']."</a>
</td>
<td><a id='myModal1' href='mailto:".$admin['email_address']."' target='_top'>".$admin['email_address']."</td>
<td>".$admin['date_joined']."</td>
<td>".$admin['group_admin']."</td>
<td>";if($admin['admin_level'] == 0 || if($admin['admin_level'] == 1 || $admin['admin_level'] == 9)
{
echo "<a href='admindelete.php?table_id=".$admin['table_id']."'><span class='label label-danger'>REMOVE</span></a></td>";
}
else
{
echo "";
}
echo "
</tr>
</tbody>
";
}
And Line 11 is this:
<td>";if($admin['admin_level'] == 0 || if($admin['admin_level'] == 1 || $admin['admin_level'] == 9)
So what is the problem with that?
You can use multiple condition in same if statement
Change
if($admin['admin_level'] == 0 || if($admin['admin_level'] == 1 || $admin['admin_level'] == 9)
To
if($admin['admin_level'] == 0 || $admin['admin_level'] == 1 || $admin['admin_level'] == 9)
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');
}
This question already has answers here:
MySQL - count total number of rows in php
(11 answers)
Closed 4 years ago.
the code below is display the else statement, but when $getlogin == 0 it is not displaying
while ($getlogin = mysql_fetch_array($checklogin)) {
if ($getlogin == 0) {
echo "NOTHING TO DISPLAY";
}
else{
echo $getlogin['username'];
echo $getlogin['password'];
}
}
$checklogin = mysql_query($queryContents);
if(mysql_num_rows($checklogin)== 0){
echo "NOTHING TO DISPLAY";
}
else{
while($getlogin = mysql_fetch_array($checklogin)) {
var_dump($getlogin);
}
}
you can use php empty function also to check empty
like this
if (empty($checklogin)) {
echo 'NOTHING TO DISPLAY';
}else{
while($getlogin = mysql_fetch_array($checklogin)) {
var_dump($getlogin);
}
}
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Please professional programmers in the house, what is wrong with this code?
I get this error whenever i try to run it.
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\a\go.php on line 8
The php code:
<?php
$term=$_POST['term'];
$level=$_POST['level'];
if (
$term = 'First';
$level='js1';
)
{
header("Location: result.php");
exit();
}
elseif (
$term = 'First';
$level='js2';
)
{
header("Location: result2.php");
exit();
}
else {
$error = "Entry is invalid";
}
?>
Check your if condition. The if and else if conditions must not contain any semicolons. If you are using two comparisons you must use && or || in between them. If you are using = in the if and elseif statement then it will always return true.
<?php
$term=$_POST['term'];
$level=$_POST['level'];
if ($term == 'First' && $level=='js1')
{
header("Location: result.php");
exit();
}
else if ($term == 'First' && $level='js2')
{
header("Location: result2.php");
exit();
}
else {
$error = "Entry is invalid";
}
?>
Change your if condition
it should be
if($term = 'First'&& $level='js1') or if($term = 'First'|| $level='js1')
elseif ($term = 'First' && $level='js2') or elseifif($term = 'First'|| $level='js2')
not
if ($term = 'First'; $level='js1';)
elseif ($term = 'First' ; $level='js2';)
All of your if statements have a malformed format. All you are doing is setting variables within your if statement. Therefore you are not using assignment operators properly. An example of how your if statement should look is:
if($condition === true || $condition2 == 'hello'){
doSomething();
} else if($condition === false || $condtion2 == 'bye'){
doSomethingElse();
}
EDIT: Also i would recommend working on your code indentation skills, this will really help to read your code in the future.
You are not making correct boolean expressions in those ifs.
if ($term === 'first' && $level === 'js1') {...}
elseif($term === 'First' && $level === 'js2') {...}
Also, I strongly recommend you to put a die(); after a redirect to avoid unnecessary load (unless you need to execute code after the redirect).
try this.
<?php
$term=$_POST['term'];
$level=$_POST['level'];
if( $term == 'First' && $level=='js1'){
header("Location: result.php");
exit();
} elseif ( $term == 'First' && $level=='js2'){
header("Location: result2.php");
exit();
} else {
$error = "Entry is invalid";
}
?>
If there is a header already sent error you receive then put ob_start() to top of your php file OR You can also use javascript for this like below.
<script>window.location.href = "a.php";</script>
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';
}