How can i fix my undefined index: title. Why is this happining? I already tried to define index title but it did not work
Before i used href, it worked perfectly.
<td><?= isset($restaurant_result['title']) ? $restaurant_result['title'] : '<span style="color:red">MANGLER</span>'; ?></td>
After implementing href, I am getting a undefined index: title in this statement.
<td><a href="restaurantoversigt?email=<?php echo $restaurant_result['title']?>"> <?= isset($restaurant_result['title']) ? $restaurant_result['title'] : '<span style="color:red">MISSING</span>'; ?></a></td>
You are missing isset check use the following:
<?php $title = isset($restaurant_result['title']) ? $restaurant_result['title'] : ""; ?>
<td><a href="restaurantoversigt?email=<?php echo $title ?>"> <?= $title != "" ? $title : '<span style="color:red">MISSING</span>'; ?></a></td>
try
array_key_exists('title', $restaurant_result) ? $restaurant_result['title'] : '<span style="color:red">MISSING</span>'
$restaurant_result['title']
is undefined. You weren't getting the error before because you were checking if it was undefined with isset
before trying to use it.
try this :
<?php
$title = isset($restaurant_result['title'])?$restaurant_result['title'] :"";
?>
<?php if($title){ ?>
<td><a href="restaurantoversigt?email=<?php echo $title;?>"> <?= $title ?></a></td>
<?php } else {?>
<td><a href="restaurantoversigt?email=<?php echo $title;?>"> <span style="color:red">MISSING</span></a></td>
<?php }?>
NOTE : in else condition there will be $title
null, so href will be : restaurantoversigt?email=
<?php
$title = null;
if (isset($restaurant_result['title']))
$title = $restaurant_result['title'];
?>
<td><a href="restaurantoversigt?email=<?php echo $title; ?>"> <?= $title !== null ? $title : '<span style="color:red">MISSING</span>'; ?></a></td>
Try this:
<td><a href="restaurantoversigt?email=<?php echo $restaurant_result['title']?>"> <?php echo isset($restaurant_result['title']) ? $restaurant_result['title'] : '<span style="color:red">MISSING</span>'; ?></a></td>