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>

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();
   }
?>

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.