Search code examples
phpexitdie

PHP - Echo and die


I realize or die("message") prints the message and exits, but how can I echo the message and exit?

$resolveGet = mysql_query($sqlGet) or exit("<span style='padding-left:10px;'>No results matching search term provided.</span>");

Solution

  • You particular code can be also written differently, because what you have there is a logical or:

    $resolveGet = mysql_query($sqlGet);
    if (!$resolveGet ) {
        // exit("<span style='padding-left:10px;'>No results matching search term provided.</span>");
    
        // can rewrite this as 
        echo "<span style='padding-left:10px;'>No results matching search term provided.</span>";
       die(); // or exit;  // whatever
    }