I have the following php (PDO) statement:
<?php echo'Call recording' ?>
How do I add a function so that if RecordURL is null, then the following HTML is echoed instead:
No call recording
My guess so far results in syntax errors:
1 <?php
2 if ($row['RecordURL'] !== null) {
3 echo'Call recording'
4 };
5 ?>
** Edit: Syntax error output: **
Parse error: syntax error, unexpected '.' in line 3
<?php
$url=$row['RecordURL'];
if (!empty($url)) {
echo'Call recording';
}else{
echo 'No call recording';
}
?>
if(!empty($row["RecordUrl"])){
echo "Record url is : ".$row["RecordUrl"];
}
Try like this,
<?php
if ($row['RecordURL'] === null) {
echo'No Call recording';
}else{
echo'Call recording';
}
?>
Variable is already set from DB so just check null value using this line
<?php echo $row['RecordURL'] ? 'Call recording' : 'No call recording'; ?>
The above should also fix your syntax error as you have ; after } - It should be before }
Related
the below script throws an error before the results the script executed. Though i get the results i want but i want to get rid of the error that throws up.
When the results equals to 1 the error doesn't show up, but when its more than 1 the error comes.
Notice: Trying to get property of non-object in
C:\xampp\htdocs\server_scripts\complains_list.php on line 1
if(count($customers->User_Name)=='1') {
echo json_encode(array($data));
}else
{
echo json_encode($data);
}
You just need to check that variable is set or not, check manual
if(isset($customers->User_Name) && count($customers->User_Name)=='1')
{
echo json_encode(array($data));
}
else
{
echo json_encode($data);
}
I guess that at some point your $customer isn't instantiated. Thus you have to test for its existence :
if($customer != null && count($customers->User_Name)=='1') {
echo json_encode(array($data));
} else {
echo json_encode($data);
}
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:
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";
};
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
}
<?php
require_once('Auth/Auth-1.6.4/Auth.php');
class MyAuth extends Auth
{
function custom_login( $username = null, $status = null )
{
if( $status == AUTH_WRONG_LOGIN )
$status_msg = 'nameORpasswordWRONG';
else
$status_msg = '';
echo <<<LOGIN_FORM
LOGIN_FORM;
}
}
?>
I get the following error:
syntax error, unexpected $end
I got this error when I added the following lines:
echo <<<LOGIN_FORM
LOGIN_FORM;
I checked }, but they seem to correct. Can somebody help me?
There must be no whitespace between the new line and the closing LOGIN_FORM;
See the big warning in the documentation
Heredoc style string enders cannot be indented.
When using HEREDOCs, the end tag must be on the line by itself. No white space before it.
<?php
require_once('Auth/Auth-1.6.4/Auth.php');
class MyAuth extends Auth
{
function custom_login( $username = null, $status = null )
{
if( $status == AUTH_WRONG_LOGIN )
$status_msg = 'nameORpasswordWRONG';
else
$status_msg = '';
echo <<<LOGIN_FORM
LOGIN_FORM;
}
}
?>
Make sure there's no whitespace before LOGIN_FORM;.
LOGIN_FORM has to be flush with the very left. See the PHP documentation on HEREDOCs