我想使用html链接将php变量传递到另一个页面 这是我的代码
<?php
$error = '';
if(isset($_POST['is_login'])){
$sql = "SELECT * FROM ".$SETTINGS["USERS"]." WHERE `email` = '".mysql_real_escape_string($_POST['email'])."' AND `password` = '".mysql_real_escape_string($_POST['password'])."'";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
$user = mysql_fetch_assoc($sql_result);
if(!empty($user)){
$_SESSION['user_info'] = $user;
$query = " UPDATE ".$SETTINGS["USERS"]." SET last_login = NOW() WHERE id=".$user['id'];
mysql_query ($query, $connection ) or die ('request "Could not execute SQL query" '.$query);
}
else{
$error = 'Wrong email or password.';
}
}
if(isset($_GET['ac']) && $_GET['ac'] == 'logout'){
$_SESSION['user_info'] = null;
unset($_SESSION['user_info']);
}
?>
<?php if(isset($_SESSION['user_info']) && is_array($_SESSION['user_info'])) { ?>
<form id="login-form" class="login-form" name="form1">
<div id="form-content">
<div class="welcome">
<?php echo $_SESSION['user_info']['name'] ?>, you are logged in.
<br /><br />
<?php echo $_SESSION['user_info']['content'] ?>
<br /><br />
<a href="login.php?ac=logout" style="color:#3ec038">Logout</a>
<?php $user =$_GET['name']; ?>
<a href="home.php?name= <?php echo $user ?>" ac=Darshboard" style="color:#F00">Home</a>
我想通过链接<a href="home.php?name= <?php echo $user ?>".
传递变量$ user请使用上面的代码来帮助纠正我的变量$ user链接。
答案 0 :(得分:0)
一个通用示例foo.php
,在bar.php?name=baz
访问时创建指向foo.php?name=baz
的链接:
<html>
<body>
<a href="bar.php?name=<? echo $_GET['name']; ?>">Link</a>
</body>
</html>
答案 1 :(得分:0)
你的代码没问题,除了:
.container{
margin-top: 20px;
}
input{
margin: 5px;
}
答案 2 :(得分:0)
替换此
<a href="home.php?name= <?php echo $user ?>" ac=Darshboard" style="color:#F00">Home</a>
与
<a href="home.php?name=<?php echo $_SESSION['user_info']['name']; ?>" ac=Darshboard" style="color:#F00">Home</a>
你的代码没问题。