0

This is my Login Page. What code or query do i get from here and add to where i want to display the user name, for the user full name to be displayed?

<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'university portal');
define('DB_USER','root');
define('DB_PASSWORD','password007');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
/*
$ID = $_POST['user'];
$Password = $_POST['pass'];
*/
function SignIn()
{
session_start();   //starting the session for user profile page
if(!empty($_POST['UserName']))   //checking the 'user' name which is from Sign-In.html, is it empty or have some text
{
    $query = mysql_query("SELECT Username, Password, voting_status FROM voters where Username = '$_POST[UserName]' AND Password = '$_POST[password]'") or die(mysql_error());
    $row = mysql_fetch_array($query) or die(mysql_error());
    if(!empty($row['Username']) AND !empty($row['Password']))
    {

        $_SESSION['Username'] = $row['Password'];
        $_SESSION['Voting Status'] = $row['voting_status'];
        header("location:Voters Account.php");

    }
    else{
        echo "username or password is incorrect";
    }
}
}
if(isset($_POST['submit']))
{
    SignIn();
}
          ?>

This is where i want to display the user full name, so please i really need help,Thanks.

<!doctype html>
<html>
<head>
<link href="css/Layout.css" rel="stylesheet" type="text/css" />
<link href="css/Menu.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<title>Student Welcome</title>

<link rel="stylesheet" href="themes/bar/bar.css" type="text/css" media= "screen" /> 
    <link rel="stylesheet" href="nivo-slider.css" type= "text/css" media="screen" />
    <script src="jquery.min.js" ></script> 
    <script type="text/javascript" src="jquery.nivo.slider.js" ></script>
</head>

<body>
<div id="Holder">
    <div id="Header">
        <a href="Home.php"><img src="assets/Logo.png"></a>
    </div>
    <div id="NavBar">
        <nav>
        <ul>
            <li><a href="Home.php">Home</a></li>
            <li><a href="Login.php">Student Portal</a>
            <ul>
                <li><a href="Login.php">Login</a></li>
                <li><a href="Candidate Profile.php">Candidates Profile</a></li>
            </ul>
            </li>
            <li><a href="Admin.php">Admin</a></li>
            <li><a href="About Site.php">About Us</a>
            <ul>
                <li><a href="About Site.php">About Site</a></li>
                <li><a href="Contact Us.php">Contact Us</a></li>
            </ul>
            </li>
        </ul>
    </nav>
    </div>
    <div id="Content">
        <div id="PageHeading">
      <h1>&nbsp;</h1>
      <h1>&nbsp;</h1>
      <h1>&nbsp;</h1>
      <h1>Welcome, <?php echo $row_Voters_Account_Form['Fname']; ?> <?php echo $row_Voters_Account_Form['Mname']; ?> <?php echo $row_Voters_Account_Form['Lname']; ?>!</h1>
      </div>
    <div id="ContentLeft">
      <h2>Your Message Here</h2></b>
      <h6>This site is to improve the style of voting in West End University College and other school at large, if it is implementted. </h6>
      <h6>&nbsp;</h6>
      <h6>Note: Please be advice that once you have placed your  vote, you won't be allowed to login again. so there for you can only view the result from of the election from the Hoe page.</h6>
    </div>
    <div id="ContentRight">
      <form id="form1" name="form1" method="post">
      </form>
      <table width="400" border="0" align="center">
        <tbody>
          <tr>
            <td>
                <div id="slider" class="nivoSlider">
            <img src="slider/IMG-20151117-WA00011234.jpg" name="imageField" data-thumb= "slider/IMG-20151117-WA00011234.jpg" alt="" title="These are the candidates for the election"/>
            <img src="slider/FB_IMG_1484460719710123.jpg" data-thumb="slider/FB_IMG_1484460719710123.jpg" alt ="" title="These are the candidates for the election" />
            <img src="slider/FB_IMG_14845217848411234567.jpg" data-thumb= "slider/FB_IMG_14845217848411234567.jpg" alt="" title="These are the candidates for the election"/>
            <img src="slider/IMAG002012345678.jpg" data-thumb= "slider/IMAG002012345678.jpg" alt="" title="These are the candidates for the election"/>
            <img src="slider/FB_IMG_1484461298331123456.jpg" data-thumb= "slider/FB_IMG_1484461298331123456.jpg" alt="" data-transition="slideInRight" title="These are the candidates for the election"/>
            <img src="slider/FB_IMG_148446110711012345.jpg" data-thumb="slider/FB_IMG_148446110711012345.jpg" alt="" title="#htmlcaption" />
        </div>

        <script type="text/javascript">
     $(window).load(function() { 
     $('#slider').nivoSlider({ 
     effect:'random', 
     slices: 15, 
     boxCols: 8, 
     boxRows: 4, 
     animSpeed: 500, 
     pauseTime: 3000,
     startSlide: 0, 
     directionNav:true, 
     controlNav:true, 
     controlNavThumbs:false, 
     pauseOnHover:true, 
     manualAdvance:false, 
     prevText:'Prev', 
     nextText:'Next', 
     randomStart:false, 
     beforeChange:function(){}, 
     afterChange:function(){}, 
     slideshowEnd:function(){}, 
     lastSlide:function(){}, 
     afterLoad:function(){} 
     }); 
     }); 
    </script>
            </td>
          </tr>
        <table width="0" border="0" align="center">
          <tr>
            <td>
                <input type="button" name="button" id="button" value="Click here to cast your vote" onClick="window.location.href='Voting.php' ">
            </td>
          </tr>
        </table>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </tbody>
      </table>
    </div>
    </div>
    <div id="Footer"></div>
</div>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Voters_Account_Form);
?>
2

2 Answers 2

0

Print Username in row of [username]:

echo $row['Username'];
0

First of all in you login code change

 $_SESSION['Username'] = $row['Password'];

to

 $_SESSION['Username'] = $row['username'];

and if the page where you want to show the user name is the page after login just start session and display the user name like this

echo $_SESSION['Username'];

hope that helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.