Jump to content

[SOLVED] Confusion,How can i make this code more efficient?


colap

Recommended Posts

Should i edit conditional statements in the <?php ?> block to make it more efficient code?

How can i make this code more efficient?

 

<?php session_start();?>
<?php
if($_POST['ins']){
	header('Location:stp.php');
}
if($_POST['upt']){
	header('Location:byte.html');
}
?>
<html>
    <head>
        <title>Welcome</title>
    </head>

    <body>                
	<form method="post">
		 <input name="ins" type="submit" value="INSERT"/>
	</form>
	<form method="post">
		<input name="upt" type="submit" value="UPDATE"/>
	</form>
	<form method="post">
		<input name="del" type="submit" value="DELETE"/>
	</form>
    </body>
</html>

Link to comment
Share on other sites

You should probably not close the PHP tag and open it again on the next line. Since only one value can be true you could use an elseif for the second parameter, but since your redirecting it won't make a whole lot of difference. THe one thing you should do is put exit(); directly after the header(); to stop the script functioning. Technically you should probably use isset also otherwise you will get a notice thrown.

 

<?php 
   session_start();

   if(isset($_POST['ins'])){
      header('Location:stp.php');
      exit();
   }
   elseif(isset($_POST['upt'])){
      header('Location:byte.html');
      exit();
   }
?>

Link to comment
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.