colap Posted October 6, 2009 Share Posted October 6, 2009 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 https://forums.phpfreaks.com/topic/176729-solved-confusionhow-can-i-make-this-code-more-efficient/ Share on other sites More sharing options...
cags Posted October 6, 2009 Share Posted October 6, 2009 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 https://forums.phpfreaks.com/topic/176729-solved-confusionhow-can-i-make-this-code-more-efficient/#findComment-931760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.