du131642 2013-02-01 15:08
浏览 9

显示登录我网站的用户名

I have this code that will check if the username and the password matched with those inside the database and that would grant the user access to my website.

<?php
$host="localhost"; // Host name 

$username=""; // Mysql username 

$password=""; // Mysql password 

$db_name="bfp6"; // Database name 

$tbl_name="station"; // Table name

// Connect to server and select database.

mysql_connect("localhost", "root", "")or die("cannot connect");


mysql_select_db("bfp6")or die("cannot select DB");

// username and password sent from form 

$mystations=$_POST['mystations']; 

$mypassword=$_POST['mypassword'];

// To protect MySQL injection

$mystations = stripslashes($mystations);

$mypassword = stripslashes($mypassword);

$mystations = mysql_real_escape_string($mystations);

$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE stations='$mystations' and password='$mypassword'";

$result=mysql_query($sql);

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){

// Register $mystations, $mypassword and redirect to file "login_success.php"

session_register("mystations");

session_register("mypassword");


header("location:main.html");

}

else {

echo "Wrong Username or Password";

}

?>

But i am really having a hard time because i don't have any idea how to insert to a new database the usernames of those who logged in in my website.I want to insert that code to this one. I have this new table named "log" with fields "id","user","time". What i want to happen is that whenever a person successfully logs in to my website, his/her username will be inserted to the table "log".Maybe with the use of $_POST but i want to make sure that the access is granted. I also already have a code that will display the contents of the table "log: if there is any.Another problem is how would the time automatically insert to the database depending on what time the user logs in. Guys, please help me. My thesis deadline is on feb 16:(

  • 写回答

2条回答 默认 最新

  • doudan4834 2013-02-01 15:17
    关注

    Set a session variable for the username, then on each page, start the session and echo out the variable. If the variable doesn't exist, log the user out.

    As for making tables, I'd suggest getting a SQL client, like heidisql, or navicat.

    Seem simple enough?

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀