Skip to content
Advertisement

login page php code not working on cpanel blank page comes after succefull login

The code is working perfectly on localhost xampp server but not working on Cpanel I think sesion_start command not working. If i login using wrong password then it shows an error its mean php code in LoinPage.php wroks but when i enter correct username and password it will show blank page instead of taking me to AdminDashboard.php
LoginPage.php

 <!DOCTYPE html>


    <html >
    <head>
      <meta charset="UTF-8">
      <title>Seza Admin Login</title>



          <link rel="stylesheet" href="css/loginStyle.css">




    </head>

    <body>


     <?php  include("connection.php");

    error_reporting(E_ALL);

            $msg=null;



            if(isset($_POST['login']) && $_POST['login']=='ok')
            {
            $username =$_POST['username'];
            $password = $_POST['password'];

            $selectuser = mysqli_query($conn,"select * from admins where USERNAME='".$username."' and PASSWORD ='".$password."'") or die(mysqli_error($conn));
            $no_users = mysqli_num_rows($selectuser);
            if($no_users>0)
                {
                    $fetch_user = mysqli_fetch_array($selectuser);
                    $_SESSION['adminid']= $fetch_user['AID'];

                    alert("success");
                    header("location:AdminDashboard.php");

                }
                else{
                    $msg = "The username or password is invalid";
                }
            }
            else{
                if(isset($_POST['login']) && $_POST['login']=='ok')
                {
                echo"invalid";  
                }
            }


         ?>
        <div class="site_wrapper">




      <form  method="post" id="additem-form" >
      <input type="hidden" id="login" name="login" value="ok" />
        <div class="login">

            <div class="login-screen">
                <div class="app-title">
                    <h1>SezaPharma</h1>
                    <h3>ADMIN LOGIN</h3>
                </div>

                <div class="login-form">
                    <div class="control-group">
                    <input type="text" class="login-field" value="" placeholder="username" id="username" name="username">
                    <label class="login-field-icon fui-user" for="login-name"></label>
                    </div>

                    <div class="control-group">
                    <input type="password" class="login-field" value="" placeholder="password" id="password" name="password">
                    <label class="login-field-icon fui-lock" for="login-pass"></label>
                    </div>

                    <button class="btn btn-primary btn-large btn-block" type="submit" value="login" >login</button>
                    <a class="login-link" onClick="alertRset()" href="">Lost ? Reset your password?</a>

                      <div style="color:#FF0004">
                    <?php 
                    if(isset($msg) && $msg!="")
                    { ?>
                        <div class="alert-danger"><?php echo $msg; ?></div> 

                         <?php }

        ?></div>
                </div>
            </div>
        </div>

        </form>


      <script>
    function alertRset() {
        var txt;
        if (confirm("It will Reset username and password to default.") == true) {
            window.close();
             window.open("resetadmin.php");
        } else {
            txt = "You pressed Cancel!";
        }
        document.getElementById("demo").innerHTML = txt;
    }
    </script>`enter code here`
    </body>
    </html>

AdminDashboard.php

<!DOCTYPE html>

<html>
<head>

</style>
</head>
<body>

<?php   include("connection.php");
error_reporting(E_ALL);

      if (isset($_SESSION['adminid'])) { 

?>

<div class="dashboard">
<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">All Products</button>
  <button class="tablinks" onclick="openCity(event, 'Paris')">Add New Product</button>
  <button class="tablinks" onclick="openCity(event, 'Tokyo')">Setting</button>
  <a href="logout.php" ><button class="tablinks" onclick="openCity(event, 'Tokyo')" >Loggout</button></a>
</div>

<div id="London" class="tabcontent" style="overflow:auto">


  <div class="site_wrapper" >




<div class="clearfix margin_top10"></div>


<div class="works01"  >

<div class="container"  >



    <div id="grid-container" class="cbp-l-grid-fullWidth"  style="overflow:visible;">


     <?php


    $select_post=mysqli_query($conn,"select * from products ORDER BY PID desc") or die(mysqli_error());

    while($post=mysqli_fetch_array($select_post))
    {

    ?>

        <div class="cbp-item <?php echo $post['PTYPE'];?>">
            <div class="cbp-caption">
                <div class="cbp-caption-defaultWrap">
                    <img style="width:100%; height:200px;" src="UploadedImage/<?php echo $post['PIMAGELOC'];?>" alt="">
                </div>
                <div class="cbp-caption-activeWrap">
                    <div class="cbp-l-caption-alignCenter">
                        <div class="cbp-l-caption-body">
                            <h3><?php echo $post['PNAME'];?></h3>
                            <br />
                            <a href="#" class="cbp-l-caption-buttonLeft">Edit</a>
                            <a href="delete_product.php?PID=<?php echo $post['PID']; ?>" class="cbp-l-caption-buttonLeft" data-title="Looking Publishing <br>reasonable always">Delete</a>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- end item -->

        <?php
        }

    ?>




    </div>



</div>
</div><!-- end works section -->













<a href="#" class="scrollup">Scroll</a><!-- end scroll to top of the page-->



</div>

</div>
<div id="Paris" class="tabcontent">
<form action="add_item.php" method="post" enctype="multipart/form-data" onsubmit="return validateForm()" id="additem-form" name="additem-form">

  <div class="contactcontainer">
  <header>
    <h1>Add new Product</h1>
  </header>
<table width="100%" align="center">
<tr>
<td  colspan="2">
    <input style="width:74%" placeholder="Product Name" type="text" id="pname" name="pname">
   </td>
   </tr>

<tr>
<td colspan="2">
        <select class="select"   style=" width:74%;"  name="cat" id="cat">
        <option value="Category" selected="selected">Product Category</option>
                <option value="livestock" > livestock Products</option>
                <option value="Poultry">Poultry Products</option>

          </select>  
          </td>
          </tr>
          <tr>
          <td colspan="2" >
          <div style="border:dashed;  width:75%;" align="center">
          <h4>Choose Product Picture</h4>
           <input type="file" id="pimage" name="pimage" class="input-file" title="upload Photo / video"  />
           </div>
           </td>
           </tr>

           <tr>   
         <td>
         <select  class="select" style=" width:55%;" id="ptype" name="ptype">
                <option value="Type">Product Type</option>
                <option value="Injections">Injections</option>
                <option value="Anthilmentics">Anthilmentics</option>
                <option value="Natural">Natural Products</option>
              </select>
              </td>
              <td>
              <select class="select" id="availability"  style=" width:55%;"  name="availability">
                <option value="Availability">Availability</option>
                <option value="yes">Yes</option>
                <option value="no">No</option>
              </select>
              </td>
   </tr>
 <tr>
<td colspan="2">
    <input style="width:74%" class="email" placeholder="Full Farmula with quantity" type="text" id="pfarmula" name="pfarmula">
  </td>
  </tr>
  <tr>
<td colspan="2">
    <textarea style="width:74%" placeholder="Product Description" id="pdesc" name="pdesc"></textarea>
    </td>
    </tr>
<tr>
<td colspan="2" >
<div style="width:74%" align="center">
  <footer>
    <button style="width:20%" id="addbtn" name="addbtn" >Add</button>
  </footer>
  </div>
  </td>
  </tr>
  </table>
</div>
</form>

</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>
</div> <!--end of tabs-->


<script>


 function validateForm()
    {
    var a=document.forms["additem-form"]["availability"].value;
    var b=document.forms["additem-form"]["pname"].value;
    var c=document.forms["additem-form"]["cat"].value;
    var d=document.forms["additem-form"]["ptype"].value;

    if (a=="Availability" || b=="" || c=="Category" || d=="Type")
      {
      alert("Please Fill All Required Field");
      return false;
      }
    }



function openCity(evt, cityName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " active";
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>



<!-- ######### JS FILES ######### -->
<!-- get jQuery used for the theme -->
<script type="text/javascript" src="js/universal/jquery.js"></script>
<script src="js/style-switcher/styleselector.js"></script>
<script src="js/animations/js/animations.min.js" type="text/javascript"></script>
<script src="js/mainmenu/bootstrap.min.js"></script> 
<script src="js/mainmenu/customeUI.js"></script> 
<script src="js/scrolltotop/totop.js" type="text/javascript"></script>
<script type="text/javascript" src="js/mainmenu/sticky.js"></script>
<script type="text/javascript" src="js/mainmenu/modernizr.custom.75180.js"></script>
<script type="text/javascript" src="js/cubeportfolio/jquery.cubeportfolio.min.js"></script>
<script type="text/javascript" src="js/cubeportfolio/main31.js"></script>

      <?php } else{ echo " You mus Loggedin to acces this page"; }   ?>
</body>
</html> 

connection.php

<?php

 session_start();
 // Create connection
 $conn = mysqli_connect("localhost", "username","password", "sezaphar_sezapharmadb") or die($conn->connect_error);

?>

Advertisement

Answer

You have a bug in the code.
You need to echo the alert(“success”) before header(“location:AdminDashboard.php”); in LoginPage.php

Here’s the code:

echo "<script>alert('success');</script>";
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement