-1
我之前在註冊頁面上獲得了一些幫助,但現在我無法獲得登錄頁面。我的登錄頁面無法正常工作
這裏是登錄代碼:
<?php
session_start();
if(isset($_SESSION['user']))
{
echo "WELCOME you are logged in";
}
if(isset($_POST['user']) && isset($_POST['password']))
{
$user = mysql_real_escape_string($_POST['username']);
$password = shal1($_POST['password']);
$db = connect('jsnow_jsnow','missysnow2005');
$eval = validate($db,$username,$password);
}
if($eval!=false)
{
echo "Welcome ".$eval;
$_SESSION['username']=$eval;
}
function connect($dbuser, $dbpassword)
{
try
{
$db = new PDO('mysql:host=localhost;dbname=jsnow_members', 'jsnow_jsnow', '*******');
return $db;
}
catch(PDOException $e)
{
echo $e;
return false;
}
}
function validate($db, $user,$password)
{
$username=false;
$query = "Select username,password FROM jsnow_members where username ='".$user."' AND password = '".$password."'";
try
{
$db->beginTransaction();
$result = $db->query($query);
foreach($result as $row)
{
$username = $row['username'];
}
$db->commit();
return $username;
}
catch(Exception $e) {}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="http://vps8383.inmotionhosting.com/~jsnow/login.php">
username: <input type="text" name="username"/>
password: <input type="password" name="password"/>
<input type="submit"/>
</body>
</html>
數據庫名稱爲jsnow_members
及其字段是username
,password
和email.
我從一個教程這個代碼,並沒有做成過很明顯,我從同一個教程中獲得了註冊頁面代碼,並且從這裏的人員那裏得到了一些工作和建議,以使其正確運行。
這裏是填補與登記信息數據庫中的註冊頁面的代碼....
<?php
if(isset($_POST['username']) && isset($_POST['password']))
{
$db =connect('jsnow_jsnow','******');
if($db!=false)
{
register($db);
echo "User registered";
}
}
function connect($dbuser, $dbpassword)
{
try
{
$db = new PDO('mysql:host=localhost;dbname=login',$dbuser,$dbpassword);
return $db;
}
catch(PDOException $e)
{
echo $e;
return false;
}
}
function register($db)
{
$user = mysql_real_escape_string($_POST['username']);
$password = shal($_POST['password']);
$email = mysql_real_escape_string($_POST['e_mail']);
$query = "INSERT INTO members(username,password,email) values('".$user."','".$password."','".$email."')";
try
{
$db->eginTransaction();
$db->exec($query);
$db->commit();
echo "commit succesful";
}
catch(Exception $e){}
}
?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<form action="http://localhost/projects/login/rigister/php" method="post">
username:<input type="text" name="username"/>
password:<input type="password" name="password"/>
email<input type="text" name="e_mail"/>
<input type="submit"/>
</form>
</body>
</html>
什麼輸出你有沒有按下提交按鈕? – Hackerman
'$ db-> eginTransaction();' - 我認爲箭頭後面的缺失'b'是相關的。 – DiMono
@RobertRozas在字段中的條目清除,並且網址從 http://vps8383.inmotionhosting.com/~jsnow/login.php 到 http://vps8383.inmotionhosting.com/~jsnow/login.php ?用戶名= jpitty3153&密碼= missysnow2005 這是唯一的屏幕上更改沒有錯誤或問題,但它不顯示歡迎消息.... –