我正在努力解决我的问题,以将用户链接到他发布的反馈。我有 feedback.php 页面,会员和非会员都可以向管理员提交反馈。我有一个功能,如果用户登录并在他登录时发送反馈,他稍后将能够在他的个人资料页面中预览他的反馈。
我在我的 Dbase 中创建了 3 个表,它们是(用户、反馈、用户信息)。
用户 tbale 有: ('userid' ,'fname', 'lname', 'username', 'email', 'password') userid(pk)
反馈表有:('feedbackid' ,'feedbacktitle', 'name', 'email', 'comment', 'datetime') feedbackid (pk)
用户信息表有: ('id', 'feedback-id', 'user-id') id(pk) feedback-id(fk) user-id(fk)
我尝试在用户表和反馈表中添加(Fk)以显示发送反馈但不能的用户。然后我创建了用户信息,试图得到我想要的东西,但什么都没有。
这是我的 feedback.php 页面:
<?php
require('Connections/portdb.php');
//start session
if(!isset($_SESSION))
{
session_start();
}
if (isset($_POST['submit'])){
$feedbacktitle = mysql_real_escape_string ( $_POST['feedbacktitle']);
$name = mysql_real_escape_string ( $_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$comment = mysql_real_escape_string($_POST['comment']);
$datetime= mysql_real_escape_string (date ("y-m-d h:i:s")); //date time
$sql= "INSERT INTO feedback(feedbacktitle, name, email, comment, datetime)
VALUES('$feedbacktitle', '$name', '$email', '$comment', '$datetime')";
$result = mysql_query($sql);
if($result){
echo "Successful";
echo "<br>";
echo "<a href='../main.php'>Go back to main page</a>";
}
else {
echo "Sorry ! an error happend.";
}
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/styels.css" rel="stylesheet" type="text/css" media="screen">
<title>Feedback Page</title>
</head>
<body>
<?php include("header.php")?>
<div id="wrapper">
<div id="content">
<table width="400" border="1" cellpadding="0" align="center">
<tr>
<td align="center" bgcolor="#CCCCCC">If you would like to contact us fill out the form below<br />
<br />
<form id="feedback-form" name="feedback-form" action="feedback.php" method="post">
<table width="100%" border="0" cellpadding="3">
<tr>
<td align="right">Title:</td>
<td align="left"><label for="email"></label>
<input type="feedbacktitle" name="feedbacktitle" id="feedbacktitle" size="30"/></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="21%" align="right">Name:</td>
<td width="79%" align="left"><label for="name"></label>
<input type="text" name="name" id="name" size="30"></td>
</tr>
<tr>
<td align="right">Email:</td>
<td align="left"><label for="email"></label>
<input type="email" name="email" id="email" size="30"/></td>
</tr>
<tr bgcolor="#CCCCCC">
<td align="right">Message:</td>
<td><label for="comments"></label>
<textarea name="comment" id="comment" cols="40" rows="5"></textarea ></td>
</tr>
<tr>
<td> </td>
<td align="right"><input type="reset" name="reset" id="reset" value="Reset" />
<input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</div>
</div>
<?php include("right-side.php")?>
<?php include("footer.php")?>
</body>
</html>
这是我的 login.php
<?php
//start session
if(!isset($_SESSION))
{
session_start();
}
include("Connections/portdb.php");
if (isset($_POST['submit'])){
$username = mysql_real_escape_string ($_POST['username']);
$password = mysql_real_escape_string (md5($_POST['password']));
$getLogin = mysql_query("SELECT * FROM user WHERE username='$username' AND password = '$password' ");
$row = mysql_fetch_array($getLogin);
if(mysql_num_rows($getLogin) > 0)
{
$_SESSION['loggedin']= true;
$_SESSION['userid']= $row['userid'];
$_SESSION['username']= $row['username'];
$_SESSION['usertype']= 'user';
session_write_close();
header("location: main.php");
}
else
{
header("location:login-user.php?msg=1");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Login Page</title>
</head>
<body>
<?php include("header.php")?>
<div id="wrapper">
<table width="915" height="700" border="2" align="center" cellpadding="0" cellspacing="3" bordercolor="#003399">
<tr>
<td width="627" align="center" valign="top" bgcolor="#A7E9DA"><p> </p>
<p><b>Welcome Guest ! Please fill the fields below to login<br />
<br />
</b></p>
<?php
if(isset($_GET['msg']))
{
$message = $_GET['msg'];
if($message == 1)
echo "<span style='color:red'>Username or Password is wroong";
}
?>
<form id="userloginform" name="userloginform" action="login-user.php" method="post">
<table width="46%" border="3" align="center" cellpadding="3" cellspacing="2">
<tr bgcolor="#CCCCCC">
<td width="21%" align="left" bgcolor="#FFFFFF">Username:</td>
<td width="79%" align="left" bgcolor="#99CC99"><label for="username"></label>
<input type="text" name="username" id="username" maxlength="30" size="30"></td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">Password:</td>
<td align="left" bgcolor="#99CC99"><label for="password"></label>
<input type="password" name="password" id="password" maxlength="128" size="30"/></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#FFCC66"><input type="submit" name="submit" id="submit" value="Login" /></td>
</tr>
<tr>
<td height="132" colspan="2" bgcolor="#FFFFFF"><p><a href="forget-passowrd.php">Forgot Your Password ?</a></p>
<p><a href="register.php">New Member ?</a></p>
</td>
</tr>
</table>
</form></td>
</tr>
</table>
</div>
<?php include("footer.php")?>
</body>
</html>
那就是我所拥有的。我尝试了很多来解决,但无法解决。有人可以告诉我我做错了什么或者我应该添加什么。我不是专家,刚接触这个并尝试学习。
非常感谢你们。