2017-02-12 9 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']; 

надежда, что помогает

 Смежные вопросы

  • Нет связанных вопросов^_^