2017-02-12 59 views
0

這是我的登錄頁面。我從這裏得到什麼代碼或查詢並添加到我想要顯示用戶名的位置,以顯示用戶全名?如何從數據庫中獲取用戶的名稱,並在用戶登錄時將其顯示給用戶?

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

這是我要顯示用戶全名的地方,所以請我真的需要幫助,謝謝。在[用戶名]的行

<!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/IMAG002.jpg" data-thumb= "slider/IMAG002.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_148446110711.jpg" data-thumb="slider/FB_IMG_148446110711.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); 
?> 
+0

http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions -in-php – Progrock

+0

http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – Progrock

回答

0

打印用戶名:

echo $row['Username']; 
0

首先在你的登錄代碼變更

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

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

如果頁面你想顯示的用戶名是th登錄後Ë頁面剛開始的會話並顯示用戶名這樣

echo $_SESSION['Username']; 

希望幫助

相關問題