something is wrong with my code formatting i believe
i am still unsure of what is happening that gives this error,
i am getting the error Parse error: syntax error, unexpected T_VARIABLE, expecting '('
here is my code
<?php
$runamazonapi = false;
if $runamazonapi = true
{
"run this code"
else
}
//do nothing
{
?>
i am getting the following error on line 3 or at this part
if $runamazonapi = true
thanks for your help in advance!!
<?php
$runamazonapi = false;
if ($runamazonapi == true)
{
"run this code"
}
else
//do nothing
{
}
?>
There are a number of syntactical errors with your code, but the error means that the php parser expected to find an ( but instead found a variable. You need () around the if statement condition and you need a closing } on the first if condition. Also, you need to use the proper {} to open and close the else clause:
<?php
$runamazonapi = false;
if ($runamazonapi = true)
{
"run this code"
}
else
{
//do nothing
}
?>
Also, what you have won't work. You're assigning $runamazonapi to true, not checking if it is true. You need to use == not =:
<?php
$runamazonapi = false;
if ($runamazonapi == true)
{
"run this code"
}
else
{
//do nothing
}
?>
try
if($runamazonapi){
//run code
}else{
//do something
}
Related
Is there any way in PHP to return at else of first statement, if the second statement which is inside of first, is false
if($first == true) {
//other code which is not necessary to mention here!
if($second == true){
// do smth
}
else{
return to the else of $first statement
}
//other code which is not necessary to mention here!
}
else{
//do smth else
}
Yes, there are multiple ways. For starters, just combine both the statements and give another condition:
if ($first == true && $second == true) {
// do smth
} elseif ($first == true && $second == false) {
// else of$first statement
} else {
//do smth else
}
This can be used as a guidance to get an idea to start. But if you can get a real world example, there can be conditions grouped, tailored to your requirement.
While there is no native way to jump to outer elses from an inner else, but you can set a flag for later processing:
$do_else = false;
if($first == true) {
//other code which is not necessary to mention here!
if($second == true){
// do smth
}
else{
$do_else = true;
}
//other code which is not necessary to mention here!
}
else{
$do_else = true;
//do smth else
}
if($do_else){
//do smth else
}
If the answers above doesn t help you in the real situation, you can create a function for execute in 'else' statements to avoid code duplication
I am trying to make my php code psr-1 psr-2 compliant Don't i am getting some weird errors actually i am not understanding what exactly it want me to solve :(
Issue-1
Error: Opening parenthesis of a multi-line function call must be the last content on the line.
if (Configuration::updateValue('AV_GTC_CT_GT_DG_CT', $AV_GTC_CT) &&
Configuration::updateValue('AV_GTC_ST_CR_GP', $AV_GTC_ST) &&
Configuration::updateValue('AV_GTC_SD_NN_EA_AR_CN_AT_CT', $AV_GTC_SD) &&
Configuration::updateValue('AV_GTC_SD_NN_EA_AR_BK_CN', $AV_GTC_SD_NN_EA_AR_BK_CN) &&
Configuration::updateValue('AV_GTC_SW_GT_TO_CR_AT_BN_AT_OR_AS_PE',
$AV_GTC_SW_GT_TO_CR_AT_BN_AT_OR
) &&
Configuration::updateValue('AV_GTC_CN_CE_FR_LG_CR_CN', $AV_GTC_CN)
) {
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
Issue-2
Error:Expected "if (...) {\n"; found "if (...)\n {\n"
if (!$customer->isGuest())
{
return false;
}
Any Clue Guys?
Other code patches that are showing same errors
if (!$customer->isGuest()){
return false;
}
if (empty($password)){
$password = Tools::passwdGen();
}
if (empty($id_customer)||empty($id_guest)){
return false;
}
if (empty($id_guest) || empty($id_customer)){
return false;
}
Thanks!
Issue1:
&& should be on the next line
open ( and close ) should be in the same line for single line argument listing :)
can't format source here, external url: pastebin link
Issue2:
{ should be on the same line
if (!$customer->isGuest()) {
return false;
}
it is very frustrating , i am getting error - >
Parse error: syntax error, unexpected 'function' (T_FUNCTION) in
C:\xampp\htdocs\chat\inc\chat.func.php on line 6
in the following code and unable to find any solution. and my php version is 5.5.1 so i don't any point of 'older' version.
here is the code
<?php
include( 'connect.inc.php')
function get_msg() {
$que = "SELECT sender , message FROM chat ";
$run = mysqli_query($conncetion,$que)
$messages = array();
while ($message = mysql_fetch_assoc($run)) {
$messages[] = array{'sender'=>$message['sender'],'message'=>$message['message']};
}
return $messages;
}
function send_msg($sender,$message) {
if( !empty($sender) && !empty($message)) {
$sender = mysql_real_escape_string($sender);
$message = mysql_real_escape_string($message);
$query = "INSERT INTO chat VALUES('','$sender','$message') ";
if($run = mysqli_query($con,$query)) {
retur n true;
} else {
return flase;
}
} else {
return flase;
}
}
?>
You're missing a semicolon from the end of your include line at the top. I saw this when I tried to edit your post and saw all of the code. Tried formatting it for you but someone else has submitted an edit.
#user4141363, There are couple of errors in your code.Please check below code & replace with your original code.
//Below Semi-column is not there in your code.
include_once( 'connect.inc.php');
// Semicolon is missing in below line so please add semicolon as below.
$run = mysqli_query($conncetion,$que);
//Array braces wrong in your code so replace this line in your code.
$messages[] = array('sender'=>$message['sender'],'message'=>$message['message']);
//Space between return true code so it's cause syntax error.
return true;
//Return false spell mistake in your code so replace below line.
return false;
I have edited your code in your question, please copy that code & check it your end.
I have submitted some code to the redirected url and now trying to use this to echo some information out but can't figure out where I am going wrong.
I have the following code:
<?php $login_attempt = mysql_real_escape_string($_GET['login_attempt']);
if ($login_attempt) == '1'{
return 'failed';
}
?>
all I want to do is if the url has $login_attempt=1 I want to return the message 'failed' to the page.
There is no point of escaping anything if it doesn't enter anywhere important (like a database).
<?php
if ($_GET['login_attempt'] == '1') {
echo 'failed';
}
?>
Also, you have a problem in your if statement, that's corrected in the code above. Be sure to include all of the condition inside of parenthesis, and not just one side of the equality check.
Also, if you wish to display something on the screen, you should echo it, not return.
how about:
if ($login_attempt == '1'){
echo 'failed';
}
Try this one. Your error in $login_attempt == '1':
<?php $login_attempt = mysql_real_escape_string($_GET['login_attempt']);
if ($login_attempt == '1'){
echo 'failed';
return false;
}
?>
As others already mentioned you have several problems but the syntax error comes from this:
if ($login_attempt) == '1'{
it should be
if ($login_attempt == '1') {
Dont u think if ($login_attempt) == '1' should be something like this ($login_attempt == '1') Sorry...many others also suggested this :P
At the first, I must tell you that you have a mistake in your IF condition. You typed == outside of ().
In addition, you have to be aware of status of setting your variable through your URL. Check the code below. In this code, I made a function to check the status. Default status is true, and we will check it just for a negative condition. I hope it could be useful for you:
<?php
function check() {
if (isset($_GET['login_attempt'])) {
$login_attempt = mysql_real_escape_string($_GET['login_attempt']);
if ($login_attempt == '1') {
return false;
} else {
return true;
}
} else {
return true;
}
}
if (!check()) echo('Error Message');
?>
Somewhere along the line I'm adding or leaving out a { } but I just can't figure out where
<?php
if (file_exists('config.php')) {
require_once('config.php');
{
if ( $EDITED_CONFIG == false )
{
header("Location: welcome.php");
}
}
}
else (file_exists('default-config-new.php')) {
require_once('default-config-new.php');
{
if ( $EDITED_CONFIG == false )
{
header("Location: welcome.php");
}
}
}
?>
If file exists require it and if edited = false redirect, if true end script.
else
If file exists require it and if edited = false redirect, if true end script.
So if the first file doesn't exist it mustn't require it or look for edited, it must skip to the second file and if that exists it must checked edited and then if is false then redirect. If the first file is true it must end script and load page. So it mustn't check second file if first file is true.
Also is this the lightest way to do this?
Thanks
If you indent your code properly, your error will become evident.
A few links that may be useful:
Wikipedia: Indent style
How to indent code
PHP Coding standard: Indentation
You're not closing your if statements: Should be something like:
<?php
if (file_exists('config.php')) {
require_once('config.php');
if ($EDITED_CONFIG == false) {
header("Location: welcome.php");
}
}
else{
require_once('default-config-new.php');
if ($EDITED_CONFIG == false) {
header("Location: welcome.php");
}
}
?>
Edited. Also, you need to close brackets around all code to be executed for that statement, before you can use another elseif or else statement:
if ($x == 1) {
echo "X is 1!";
}
else if ($x == 0) {
echo "X is 0!";
}
else {
echo "Not 1 or 0!";
}
You are missing the { after the else to enclose what you want inside the "else" block i believe
You need to write
else if (conditions...)
You have got
else (conditions...)