|
|
|
ปัญหาการทำระบบ login ไม่ได้ เกี่ยวกับ mysql_fetch_row ของ php mysql |
|
|
|
|
|
|
|
ลองใส่ session_start(); ดูนะค่ะ
Code (PHP)
<?php
session_start();
include("../connectdb.php");
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$sql = "select * from tbadmin where admin_username = '".$_POST['txtUsername']."' and admin_password = '".$_POST['txtPassword']."'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num > 0)
{
$rs = mysql_fetch_array($result);
$_SESSION['admin_login'] = $rs["admin_id"];
echo "<script> window.location='product.php';</script>";
}
else
{
echo "<script> alert('ชื่อหรือรหัสผ่านไม่ถูกต้องค่ะ'); window.location='../index.php';</script>";
}
?>
|
|
|
|
|
Date :
2012-05-20 17:21:04 |
By :
kankanit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ครับ
จะลองทำดูก่อน
|
|
|
|
|
Date :
2012-05-20 17:48:54 |
By :
velona |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้นี่
$DBquery=mysql_db_query($DBName, $sql) or die(mysql_error() . "<br/>" . $sql);
แทนนี่
$DBquery=mysql_db_query($DBName, $sql);
จำได้เห็นว่า error เพราะอะไร ส่วนมากก็ตัวแปรไม่มีค่าเพราะไม่ได้ใช้ $_GET $_POST ครับ
|
|
|
|
|
Date :
2012-05-20 18:01:30 |
By :
ikikkok |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลองแก้ใหม่ มันก็ยังตอบเหมือนเดิมครับและมันก็ไม่แสดง error อย่างที่คุณ PlaKriM แนะนำครับ
Code (PHP)
<?
include("ConnectDB.php");
$user=$_POST['user'];
$pw=$_POST['pw'];
$sql = "SELECT * FROM staff WHERE Username = '".trim($_POST['user'])."'
and Password = '".trim($_POST['pw'])."'";
$DBquery=mysql_db_query($DBName, $sql) or die(mysql_error() . "<br/>" . $sql);
$num_rows = mysql_fetch_row($DBquery);
if($num_rows == 1)
{
echo " ข้อมูลถูกต้อง" ;
}
else {
echo "ข้อมูลผิด";
}
?>
|
|
|
|
|
Date :
2012-05-20 19:23:39 |
By :
velona |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ที่ mysql_fetch_row ใช้ mysql_num_rows แทนก็ได้แล้วละครับ
|
|
|
|
|
Date :
2012-05-20 20:21:10 |
By :
narubet |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
session_start();
mysql_connect("localhost","root","root");
mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM member WHERE Username = '".trim($_POST['txtUsername'])."'
and Password = '".trim($_POST['txtPassword'])."'";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Username and Password Incorrect!";
}
else
{
$_SESSION["UserID"] = $objResult["UserID"];
$_SESSION["Status"] = $objResult["Status"];
session_write_close();
if($objResult["Status"] == "ADMIN")
{
header("location:admin_page.php");
}
else
{
header("location:user_page.php");
}
}
mysql_close();
?>
|
|
|
|
|
Date :
2012-05-21 06:27:09 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
include("ConnectDB.php");
$user=$_POST['user'];
$pw=$_POST['pw'];
$sql = "SELECT * FROM staff WHERE Username = '".trim($_POST['user'])."'
and Password = '".trim($_POST['pw'])."'";
$DBquery=mysql_db_query($DBName, $sql) or die(mysql_error() . "<br/>" . $sql);
$num_rows = mysql_num_rows($DBquery); // เปลี่ยนตรงนี้ดูยังครับ
if($num_rows == 1)
{
echo " ข้อมูลถูกต้อง" ;
}
else {
echo "ข้อมูลผิด";
}
?>
|
|
|
|
|
Date :
2012-05-21 15:37:18 |
By :
keng_ds |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$sql = "select * from staff where Username = '".$_POST['username']."' and Password = '".$_POST['password']."' ";
|
|
|
|
|
Date :
2012-05-21 16:04:38 |
By :
katwalks |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|