Petite-Dragon Posted January 27, 2015 Share Posted January 27, 2015 im having trouble inserting the <script> code in the die here is my code <?php session_start (); $username = $_POST ['username']; $password = $_POST ['password']; if ($username&&$password) { $connect = mysql_connect ("localhost","root","") or die("Error"); mysql_select_db('thesis') or die("Error"); $query = mysql_query("SELECT * FROM student WHERE username ='$username'"); $numrows = mysql_num_rows($query); $query1 = mysql_query("SELECT * FROM admin WHERE username='$username'"); $row1 = mysql_fetch_assoc($query1); $adusername = $row1['username']; $adpassword = $row1['password']; $queryid = mysql_query("SELECT id FROM student WHERE username ='$username'"); $row2 = mysql_fetch_assoc($queryid); $id = $row2['id']; if ($username==$adusername&&$password==$adpassword) { die(strval($_SESSION['username']=$username)); die ('<script type="text/javascript"> alert("Welcome Administrator !"); window.location = "adminpage.php"; </script>'); } if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { echo '<script type="text/javascript"> alert("Login Successful !"); window.location = "studhome.php"; </script>'; $_SESSION['username']=$username; $_SESSION['id']=$id; $_SESSION['name']=$name; } else echo '<script type="text/javascript"> alert("Incorrect Password !"); window.location = "Login.php"; </script>'; } else die('<script type="text/javascript"> alert("User not Registered !"); window.location = "Login.php"; </script>'); } else die('<script type="text/javascript"> alert("Please Enter Username/Password !12121"); window.location = "Login.php"; </script>'); ?> advance thanks Quote Link to comment https://forums.phpfreaks.com/topic/294261-little-help-in-php/ Share on other sites More sharing options...
QuickOldCar Posted January 30, 2015 Share Posted January 30, 2015 I would use header versus all the javascript Quote Link to comment https://forums.phpfreaks.com/topic/294261-little-help-in-php/#findComment-1504346 Share on other sites More sharing options...
cyberRobot Posted January 30, 2015 Share Posted January 30, 2015 It may help if you provide more information on what you are hoping to do. For what it's worth, only the first call to the die() function will be executed. The second call never gets executed since die() terminates the PHP script. More information can be found here: http://php.net/manual/en/function.die.php Quote Link to comment https://forums.phpfreaks.com/topic/294261-little-help-in-php/#findComment-1504356 Share on other sites More sharing options...
Tom8001 Posted January 31, 2015 Share Posted January 31, 2015 Why not echo the data and then kill the script? Quote Link to comment https://forums.phpfreaks.com/topic/294261-little-help-in-php/#findComment-1504468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.