มีปัญหาเรื่อง login ครับ ช่วยดูให้หน่อยนะครับ มีรูป และโค้ดให้ดูด้วยครับ
ผมรู้แค่ว่าไม่สามารถเชื่อมต่อ mysql ได้ แต่ไม่รู้สาเหตุครับ พยามแก้มา 2 วันล่ะ ไม่ได้ซักที
ถึงต้องเข้ามารับกวนถามผู้รู้ครับ
Date :
2012-02-11 09:19:04
By :
9vespa
ลองตรวจสอบเรื่องการเชื่อมต่อข้อมูลดูครับ หรือไม่ก็เอาไฟล์ที่ใช้ connect db มาดูด้วยก็ดีครับ
Date :
2012-02-11 09:31:22
By :
pokultra
Code (PHP)
<?
$database = "urbanfloristsupplies";
$hostname = "localhost";
$username = "root";
$password = "1234";
$conn = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $conn);
?>
นี่คือไฟล์ connect DB ครับ
Date :
2012-02-11 09:35:07
By :
9vespa
Code (PHP)
<?php
require_once "../include/connectdb.php";
$sql = "select * from useradmin where useradmin = '{$_POST["useradmin"]}' and passadmin = md5('{$_POST["passadmin"]}');
$dbquery = mysql_query($sql) or die(mysql_error()."<br />your query string : $sql");
$num_rows = mysql_num_rows($dbquery);
$rowLogin = mysql_fetch_array($dbquery);
if($num_rows == 1){
session_start();
$_SESSION['useradmin'] = $rowLogin['useradmin'];
echo "<meta http-equiv='refresh' content='0';URL='Admin.html'>";
}else{
echo "<meta http-equiv='Content-Type' content='text/html; charset=tis-620' />";
echo "<script language='javascript'>alert('Username or password is incorrect. Please check again.');</script>";
echo "<meta http-equiv='refresh' content='0';URL='index.phpl'>";
}
?>
Date :
2012-02-11 10:55:22
By :
Unidentier
ขอบคุณครับ แต่ก็ยังไม่ได้
Date :
2012-02-11 13:15:04
By :
9vespa
ตกเครื่องหมายคำพูด (double quote) ปิดไปตัวนึงครับ
$sql = "select * from useradmin where useradmin = '{$_POST["useradmin"]}' and passadmin = md5('{$_POST["passadmin"]}') ";
Date :
2012-02-11 13:34:55
By :
Unidentier
เอา code หน้า signin มาดูครับ
Date :
2012-02-11 13:46:42
By :
slurpee55555
ขอโค้ดหน้าฟอร์มรับข้อมูลมาดูด้วยครับ
แต่ที่แน่ๆ การเชื่อมต่อกับฐานข้อมูล username password ไม่ถูกต้องครับ
Date :
2012-02-11 15:11:24
By :
Unidentier
ตอบความคิดเห็นที่ : 11 เขียนโดย : Unidentier เมื่อวันที่ 2012-02-11 15:11:24
รายละเอียดของการตอบ ::
นี่คือฟอร์ม login ครับ
Code (PHP)
<!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>ADMINISTRATOR | Urban Florist Supplies</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
headerclass: "submenuheader",
contentclass: "submenu",
revealtype: "click",
mouseoverdelay: 200,
collapseprev: true,
defaultexpanded: [],
onemustopen: false,
animatedefault: false,
persiststate: true,
toggleclass: ["", ""],
togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast",
oninit:function(headers, expandedindices){
},
onopenclose:function(header, index, state, isuseractivated){
}
})
</script>
<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.ask').jConfirmAction();
});
</script>
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
</head>
<body>
<div id="main_container">
<div class="header_login">
<div class="logo"><a href="#"><img src="images/logo.jpg" alt="" title="" border="0" /></a></div>
</div>
<div class="login_form">
<h3>Admin Login</h3>
<a href="ForgottenPassword.php" class="forgot_pass">Forgot password</a>
<form action="SignIn.php" method="post" class="niceform">
<fieldset>
<dl>
<dt><label for="email">Username:</label></dt>
<dd><input type="text" name="textName" id="textName" size="54" /></dd>
</dl>
<dl>
<dt><label for="password">Password:</label></dt>
<dd><input name ="textPassword"type="password" id="textPassword" size="54" /></dd>
</dl>
<dl>
<dt><label></label></dt>
<dd>
<input type="checkbox" name="interests[]" id="" value="" /><label class="check_label">Remember me</label>
</dd>
</dl>
<dl class="submit">
<input type="submit" name="submit" id="submit" value="Login" />
</dl>
</fieldset>
</form>
</div>
<div class="footer_login">
<div class="left_footer_login"><span class="left_footer">Administrator | Powered by <a href="http://indeziner.com">UrbanFloristSuppiles</a></span></div>
<div class="right_footer_login"></div>
</div>
</div>
</body>
</html>
Date :
2012-02-11 16:06:50
By :
9vespa
Code (PHP)
<?php
require_once "../include/connectdb.php";
$sql = "select * from useradmin where useradmin = '{$_POST["textName"]}' and passadmin = md5('{$_POST["textPassword"]}') ";
$dbquery = mysql_db_query(urbanfloristsupplies, $sql) or die(mysql_error()."<br />your query string : $sql");
$num_rows = mysql_num_rows($dbquery);
$rowLogin = mysql_fetch_array($dbquery);
if($num_rows == 1){
session_start();
$_SESSION['useradmin'] = $rowLogin['useradmin'];
echo "<meta http-equiv='refresh' content='0';URL='Admin.html'>";
}else{
echo "<meta http-equiv='Content-Type' content='text/html; charset=tis-620' />";
echo "<script language='javascript'>alert('Username or password is incorrect. Please check again.');</script>";
echo "<meta http-equiv='refresh' content='0';URL='index.php'>";
}
?>
แล้วแก้ปัญหาเรื่องเชื่อมต่อเดต้าเบสหรือยังครับ
Date :
2012-02-11 16:11:01
By :
Unidentier
ลองเข้า phpMyAdmin ด้วย username : root และ password : 1234
ทดลองดูว่าเข้าได้มั๊ย
Date :
2012-02-11 16:35:49
By :
Unidentier
ในหน้า SignIn ลองแก้
Code (PHP)
$sql = "select * from useradmin where useradmin = '{$_GET[useradmin]}' and passadmin = ".md5($_GET["passadmin"]);
Date :
2012-02-11 16:36:15
By :
slurpee55555
ตอนนี้ติดปัญหาส่วนไหนครับ
Date :
2012-02-11 16:51:47
By :
Unidentier
<?php
require_once "../include/connectdb.php";
$sql = "select * from useradmin where useradmin = '{$_POST["textName"]}' and passadmin = md5('{$_POST["textPassword"]}') ";
$dbquery = mysql_db_query(urbanfloristsupplies, $sql) or die(mysql_error()."<br />your query string : $sql");
$num_rows = mysql_num_rows($dbquery);
$rowLogin = mysql_fetch_array($dbquery);
if($num_rows == 1){
session_start();
$_SESSION['useradmin'] = $rowLogin['useradmin'];
echo "<meta http-equiv='refresh' content='0';URL='Admin.html'>";
}else{
echo "<meta http-equiv='Content-Type' content='text/html; charset=tis-620' />";
echo "<script language='javascript'>alert('Username or password is incorrect. Please check again.');</script>";
echo "<meta http-equiv='refresh' content='0';URL='index.php'>";
}
?>
ให้เปลี่ยนเป็น
$dbquery = mysql_query($sql) or die(mysql_error()."<br />your query string : $sql");
Date :
2012-02-11 17:01:53
By :
Unidentier
ตอนนี้ตัดสินใจลง Appserv ใหม่ไปแล้วครับ ได้แต่หวังว่ามันจะได้นะครับ 55+
Date :
2012-02-11 17:08:31
By :
9vespa
authentic.php
Code (PHP)
<?php
session_start();
if(isset($_POST["submitForm"]) && isset($_POST["account"]) && isset($_POST["passwd"])){
include("my_class.php");
$newDB = new DBs();
$newDB->connect();
$sql = "select * from authentic where username='".mysql_real_escape_string($_POST["account"])."' and passwd=md5('".mysql_real_escape_string($_POST["passwd"])."') and (expiredate > curdate() or expiredate is null )";
$newDB->dbquery($sql);
$alertText="";
if(mysql_num_rows($newDB->result)>0){
$dat = mysql_fetch_assoc($newDB->result);
$_SESSION["authorized"]="yes";
$_SESSION["account"]=$dat["username"];
$_SESSION["level"]=$dat["level"];
$_SESSION["nick"]=$dat["nick"];
$_SESSION["fullname"]=$dat["fullname"];
echo "<script language=\"javascript\">window.location='./';</script>";
}else{
$alertText="<div style=\"margin-top:3em;width:400px;-moz-border-radius:15px;border-radius:10px;opacity:0.75;display:block;text-align:center;background-color:lemonchiffon;color:red\">การเข้าระบบล้มเหลว กรุณาล็อคอินใหม่อีกครั้งค่ะ</div>";
}
}
?>
<!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>
<title>ระบบงาน ....</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body onload="document.forms[0].account.focus();" >
<form method="post">
<div style="margin-top:15px;margin-left:20px;width:400px;height:150px;-moz-border-radius:15px;border-radius:10px;-moz-box-shadow: 10px 10px 5px #888;
-webkit-box-shadow: 10px 10px 5px #888;box-shadow: 10px 10px 5px #888;background-color:gray;color:white;opacity:0.85;">
<ul style="list-style:none;">
<li style="display:inline-block;width:350px;;text-align:center;font-weight:bold;padding-top:5px;font-size:1.2em;">ลงชื่อเข้าระบบงาน</li><br />
<li style="display:inline-block;width:120px;text-align:right;font-size:1em;margin-top:1em;">ชื่อผู้ใช้ระบบ</li>
<li style="display:inline-block;text-align:left;padding-left:2em;"><input type="text" name="account" id="account" style="width:140px;" onfocus="this.select();nextfield='passwd';" /></li><br />
<li style="display:inline-block;width:120px;text-align:right;font-size:1em;margin-top:0.5em;">รหัสผ่าน</li>
<li style="display:inline-block;text-align:left;padding-left:2em;"><input type="password" name="passwd" id="passwd" style="width:140px;" onfocus="this.select();nextfield='done';" /></li><br />
<li style="width:350px;text-align:center;padding-top:1em;"><input type="submit" name="submitForm" value="ยืนยันข้อมูล" /></li><br />
</ul>
</div>
<?php
echo $alertText;
?>
</form>
</body>
</html>
index.php
Code (PHP)
<?php
session_start();
if(!isset($_SESSION["authorized"])){
echo "<script language=\"javascript\">window.location='authen.php';</script>";
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ระบบงาน......</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h2 style="color:blue">คุณได้ผ่านการตรวจแล้วค่ะ</h2>
</body>
</html>
<?php
}
?>
my_class.php
Code (PHP)
<?php
class DBs{
private $host;
private $user;
private $password;
private $dbname;
private $link;
public $result;
public $data;
public function __construct($db="urbanfloristsupplies"){
$this->host="localhost";
$this->user="admin";
$this->password="1234567";
$this->dbname=$db;
}
public function connect(){
$this->link=mysql_connect($this->host,$this->user,$this->password) or die("Can't connect Database".mysql_error());
mysql_select_db($this->dbname,$this->link) or die("\"$this->dbname maybe not exist! \"".mysql_error());
@mysql_query("set names utf8");
}
public function dbquery($qstr){
$this->result = mysql_query($qstr) or die(mysql_errno().":".mysql_error().$qstr);
}
public function fetch_assoc(){
return mysql_fetch_assoc($this->result);
}
}
?>
ลองเอาไปเป็นตัวอย่างดูน่ะครับ อันนี้ที่ผมใช้อยู่เป็นประจำ
Date :
2012-02-11 17:24:51
By :
Unidentier
แก้ไขหน่อยครับ
authentic.php => authen.php
Date :
2012-02-11 17:29:13
By :
Unidentier
ตอนนี้ยังติดตรงเชื่อมต่อดาต้าเบสไม่ได้ครับ รบกวนช่วยผมทีครับ ขอบคุณครับ
Date :
2012-02-13 08:38:34
By :
9vespa
ทดลองตามนี้น่ะครับ
แก้ user ที่ $this->user
แก้ password ที่ $this->password
แล้วรันไฟล์นี้ดูครับ
Code (PHP)
<?php
class DBs{
private $host;
private $user;
private $password;
private $dbname;
private $link;
public $result;
public $data;
public function __construct($db="urbanfloristsupplies"){
$this->host="localhost";
$this->user="root";
$this->password="1234567";
$this->dbname=$db;
}
public function connect(){
$this->link=mysql_connect($this->host,$this->user,$this->password) or die("Can't connect Database".mysql_error());
mysql_select_db($this->dbname,$this->link) or die($this->dbname." maybe not exist! ".mysql_error());
@mysql_query("set names utf8");
}
public function dbquery($qstr){
$this->result = mysql_query($qstr) or die(mysql_errno().":".mysql_error().":".$qstr);
}
public function fetch_assoc(){
return mysql_fetch_assoc($this->result);
}
}
$newCon = new DBs();
$newCon->dbquery("select 10+10");
$data = mysql_fetch_row($newCon->result);
echo "<h1>".$data[0]."</h1>";
?>
Date :
2012-02-13 13:17:27
By :
sakuraei
ติดตั้ง Appserv ใหม่แล้วใช่เหรอเปล่าครับ
ลองเข้าไปที่ "MySQL Command Line Client"
จะอยู่ในโฟลเดอร์ Appserv ในเมนูสตาร์ทครับ
พอเปิดหน้าต่างๆดำ คล้ายดอสสมัยก่อน
เค้าจะถามหาพาสเวิร์ดครับ (ของยูสเซอร์รูท root น่ะครับ)
ดูซิว่าล็อคอิน่านมั๊ย ถ้าผ่านก็ลองคีย์คำสั่งง่าย show databases;
Date :
2012-02-13 16:22:57
By :
sakuraei
ตอนนี้ login ไม่มีเออเร่อแล้วครับ แต่ไม่ขึ้นอะไรเลย ครับ ฮ่าๆๆ
Date :
2012-02-14 00:22:27
By :
9vespa
ถ้าจากโค้ดตัวอย่างที่ผมให้จะมีอยู่ 3 ไฟล์
ถ้าล็อคอินผ่านเค้าจะขึ้นคำว่า คุณได้ผ่านการตรวจแล้วค่ะ
Date :
2012-02-14 07:23:51
By :
sakuraei
ตอนนี้ได้แล้วคร้าบบ ขอบคุณทุกคนมากครับผม
Date :
2012-02-14 08:40:00
By :
9vespa
Load balance : Server 04