The following line of code is creating an ‘Undefined Index’ notice.
<?php if ($_POST['title'] && empty($success)) { echo $_POST['title']; } ?>
I have tried the following line, but its wrong somehow, but I think I’m on the right lines.
<?php if (isset($_POST['title'] && empty($success)) { echo $_POST['title']; }) ?>
m3g4p0p
January 20, 2016, 10:23am
3
The first line doesn’t work because, well, the index is not defined. You have to use isset
here, but in the second line you forgot to close the brackets. Didn’t it actually throw a syntax error?
SamA74
January 20, 2016, 10:23am
4
Using the isset
the brackets are wrong.
<?php if ((isset($_POST['title'])) && (empty($success))) { echo $_POST['title'];} ?>
Ah I see yes, thanks guys
I am also getting the same issue with this line below, which I thought wouldn’t need the isset addition.
<?php echo $q['IdCntry_Hot']?>
PHP Notice: Undefined index: IdCntry_Hot
m3g4p0p
January 20, 2016, 11:07am
7
If there’s a chance that a certain element of an array is not present (yet), you have to check this with isset
. Otherwise the index might not be defined and you get the above notice, which actually says it all.
1 Like
I see, ok I didn’t know that, thank you.
Its basic, but how would I use isset on this occasion.
SamA74
January 20, 2016, 11:16am
9
<?php if(isset($q['IdCntry_Hot'])) { echo $q['IdCntry_Hot'] ; } ?>
Right I got you, thank you all
Gandalf
January 20, 2016, 11:18am
11
Your could use
echo isset($q['IdCntry_Hot'] ? $q['IdCntry_Hot'] : '';
At the start of the Php page try checking and setting the following for all possible $_POST
values.
<?php
error_reporting(-1);
ini_set('display_errors', '1');
$IdCntry = isset( $q['IdCntry_Hot'] ) ? $q['IdCntry'] : FALSE;
felgall
January 20, 2016, 7:35pm
13
The original version would be almost correct for PHP 7 where the null coalesce operator can be used instead of isset.
<?php echo $q['idCntry_Hot']??""; ?>
system
Closed
April 21, 2016, 10:46am
14
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.