php代码无法正常工作?

时间:2017-04-23 16:54:36

标签: php

"$query = ("SELECT * FROM `accounts` WHERE username = '$username'")or die(mysql_error());"

如果我不添加accountsid"$_SESSION['userid'] = $row['id'];"无法正常工作,但如果我确实添加了它,那么登录也无法正常工作accounts是数据库而id 1}}在里面。

<?php
session_start();
if(isset($_SESSION['users']) != ""){
echo '<script type="text/javascript">','index();','</script>';
}

require '../php/dbConnect.php';
    $username = $_POST['username'];
	  $password = $_POST['password'];
    $query = ("SELECT * FROM `accounts` WHERE username = '$username'")or die(mysql_error());
    $response = mysql_query($query);

	$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");
	}
?>


<div id="friend-request-title" class="overlay round-edge panel-left">
	<label class="w3-text-white "><h2><b>Friend Requests</b></h2></label>
</div>
<div id="friend-request-panel" class="overlay round-edge panel-up">
	<?php
	require 'php/dbConnect.php';
	    $query = ("SELECT * FROM `accounts` WHERE `id` <> '".$_SESSION['userid']."'");
	    $response = mysql_query($query);

	    while($row = mysql_fetch_assoc($response)) {
	      echo '
	      <div class="lesson-section">
	    		<div class="container">
	    			<img id="profile-image" src="img/profile2.png" class="big-circle float" style="margin: 4% 0 0 0;">
	    		</div>
	    		<label id="" class="w3-text-white"><h4><b>You have a new friend request.</b></h4></label>
	    		<label id="" class="w3-text-white">Friend request from '. $row['username'] .'.</label>
	    		<br>
	    		<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>
	    		<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>
	    	</div>
	    	<hr>
	      ';
	    }
	?>

1 个答案:

答案 0 :(得分:0)

你在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>';
}
相关问题