Jump to content

[SOLVED] Exit()


rawky1976

Recommended Posts

Alright all...

 

If I exit from a script using exit(); I don't get the rest of the page displayed (css puts the nav links after the code and form)

 

If I comment out (//exit()) then I get the form displayed again even after a successful insert (with sticky fields, which I don't want).

 

if($result) {
            echo 'Client successfully added, to add another <a href="addclient.php">click here</a> or use the navigation links on the right to continue working';

            //exit();

            } else {

            echo 'System Error
            <p>The client could not be added due to a system error.</p>';        
            echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';

            exit();
            }
        
        include ('./includes/closedb.php');
        
        } else {

        echo 'Error! <p>The following error(s) occurred: <br />';

        foreach($errors as $msg){
        echo " - $msg<br />\n";

        }

}
    
}

?>

			<form action='addclient.php' method='POST'>
		<fieldset>

 

I was thinking about GOTO, but the I Googled 'GOTO PHP' and the word on the street is we don't do GOTO in php_land.

 

How do we get around this then please???

Link to comment
https://forums.phpfreaks.com/topic/66941-solved-exit/
Share on other sites

exit() is used to kill the script. Once its called, your script is dead.

 

You could set a boolean to display the form, like this:


$displayForm= true;

if($result) {
            echo 'Client successfully added, to add another <a href="addclient.php">click here</a> or use the navigation links on the right to continue working';

            $displayForm=false;

} else {

      // handle your errors
    
}
?>

<?php
// And wherever you want to put the code:
if($displayForm){

  ?>

  <form><fields></form>

<?php 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/66941-solved-exit/#findComment-335674
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.