Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.