php代码无法正常工作?
问题描述:
"$query = ("SELECT * FROM `accounts` WHERE username = '$username'")or die(mysql_error());"
如果我不加accounts
,id
然后"$_SESSION['userid'] = $row['id'];"
不会工作,但如果我不加它,然后登录不会工作也accounts
是数据库和id
是它的内部。
<?php
session_start();
if(isset($_SESSION['users']) != ""){
echo '<script type="text/javascript">','index();','</script>';
}
require '../php/dbConnect.php';
$username = $_POST['username'];
\t $password = $_POST['password'];
$query = ("SELECT * FROM `accounts` WHERE username = '$username'")or die(mysql_error());
$response = mysql_query($query);
\t $row = mysql_fetch_array($response);
if($row['password'] == md5($password))
{
$_SESSION['online'] = true;
$_SESSION['users'] = $username;
$_SESSION['userid'] = $row['id'];
echo '<script type="text/javascript">','redirect();','</script>';
}
else{
echo("Wrong Credentials");
\t }
?>
<div id="friend-request-title" class="overlay round-edge panel-left">
\t <label class="w3-text-white "><h2><b>Friend Requests</b></h2></label>
</div>
<div id="friend-request-panel" class="overlay round-edge panel-up">
\t <?php
\t require 'php/dbConnect.php';
\t $query = ("SELECT * FROM `accounts` WHERE `id` <> '".$_SESSION['userid']."'");
\t $response = mysql_query($query);
\t while($row = mysql_fetch_assoc($response)) {
\t echo '
\t <div class="lesson-section">
\t \t \t <div class="container">
\t \t \t \t <img id="profile-image" src="img/profile2.png" class="big-circle float" style="margin: 4% 0 0 0;">
\t \t \t </div>
\t \t \t <label id="" class="w3-text-white"><h4><b>You have a new friend request.</b></h4></label>
\t \t \t <label id="" class="w3-text-white">Friend request from '. $row['username'] .'.</label>
\t \t \t <br>
\t \t \t <button id="" class="w3-btn w3-text-white light-overlay border-remove round-edge" style="margin: 2% 2% 0 0;" type="button"><b>Accept</b></button>
\t \t \t <button id="" class="w3-btn w3-text-white light-overlay border-remove round-edge" style="margin: 2% 0 0 0;" type="button"><b>Decline</b></button>
\t \t </div>
\t \t <hr>
\t ';
\t }
\t ?>
答
您有错误在你的PHP的这一部分:
if(isset($_SESSION['users']) != ""){
echo '<script type="text/javascript">','index();','</script>';
}
您应该使用isset再检查,如果不为空
if(isset($_SESSION['users']) && $_SESSION['users'] != ""){
echo '<script type="text/javascript">','index();','</script>';
}
+1
为什么不'echo'';'? – FrankerZ
+0
我不喜欢改变什么是没有错的:) –
请检查[这] (http://*.com/help/how-to-ask) – getl0st
Md5。真的吗? – Akintunde007
对不起我是一个noob〜 –