我的饼干不会工作! PHP + Mysql + Cookies [英] My cookie wont work! PHP + Mysql + Cookies
问题描述
// 创建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屋!