我的饼干不会工作! PHP + Mysql + Cookies [英] My cookie wont work! PHP + Mysql + Cookies

查看:56
本文介绍了我的饼干不会工作! PHP + Mysql + Cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我的网站上有一个登录页面。如果密码和用户名正确,则会创建一个cookie:

  //  创建cookie  
$ date_of_expiry = time()+ 300 ;
setcookie( userlogin 。$ _POST [' myusername']。 $ date_of_expiry );





并在创建cookie后重定向用户:header('location:shopowner.php');



在shopowner.php上,代码应该使用cookie的值显示MySQL数据:

 <?php  

$ connect = mysql_connect( localhost root die(mysql_error());

mysql_select_db( dress,$ connect);
echo 欢迎 。 $ _COOKIE [' userlogin']。 < br>;

$ sql = SELECT * FROM data WHERE Username ='。 $ _COOKIE [' userlogin']。 ';
$ result = mysql_query($ sql,$ connect);
echo ' MyData:< br> ;
while ($ row = mysql_fetch_array($ result)){
echo < span class =code-string>
。 $ row [' Shop']。 < br>;
}

?>



没有错误消息出现了。 cookies工作,因为它回显:欢迎Admin(cookie的值)但没有显示MySQL数据。如果有人愿意,请帮我弄清问题是什么。

解决方案

date_of_expiry = time()+ 300 ;
setcookie( userlogin


_POST [' myusername']。


date_of_expiry );





及之后创建一个cookie,重定向用户:header('location:shopowner.php');



在shopowner.php上,代码应该使用cookie的值显示MySQL数据:

 <?php  


Hi there! I have a login page on my website. If the password and username is correct it creates a cookie :

//create cookie
$date_of_expiry = time() + 300 ;
setcookie( "userlogin", " ". $_POST['myusername'] ."", $date_of_expiry );



and after it creates a cookie it redirects the user: header('location:shopowner.php');

On shopowner.php the code is supposed to display MySQL data using the value of the cookie:

<?php

$connect = mysql_connect("localhost", "root") or die (mysql_error());

mysql_select_db("dresses", $connect);
echo "Welcome " . $_COOKIE['userlogin'] . "<br>";

$sql = "SELECT * FROM data WHERE Username = '" . $_COOKIE['userlogin']  . "'";
$result = mysql_query($sql, $connect);
echo 'MyData:<br>';
while ($row = mysql_fetch_array($result)) {
echo   "" . $row['Shop'] . "<br>" ;
}

?>


There are no error messages that come up. the cookies work because it echo's: Welcome Admin(the value of the cookie) but no MySQL data gets displayed. If anyone would be kind enough te help me figure out what the problem is.

解决方案

date_of_expiry = time() + 300 ; setcookie( "userlogin", " ".


_POST['myusername'] ."",


date_of_expiry );



and after it creates a cookie it redirects the user: header('location:shopowner.php');

On shopowner.php the code is supposed to display MySQL data using the value of the cookie:

<?php


这篇关于我的饼干不会工作! PHP + Mysql + Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆