2013-07-27 53 views
-1

Iam与我的问题一起努力,将用户链接到他发布的反馈。我有feedback.php页面,它可供会员和非会员向管理员提交反馈。 我有一个功能,如果用户在登录时登录并发送反馈,他可以稍后在其个人资料页面中预览他的反馈。用户登录后链接用户ID和反馈ID

我创造了我的dBASE 3桌它们(用户反馈用户信息)。

用户tbale有:( '用户ID', 'FNAME', 'L-NAME', '用户名', '电子邮件', '密码')的用户ID(PK)

反馈表有:(” ('id','feedback-id','feedbacktitle','name','email', 'comment','datetime')feedbackid(pk)

user-用户ID“)的ID(PK) 反馈-ID(FK)的用户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>&nbsp;</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>&nbsp;</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> 

那我有什么。我尝试了很多解决方案,但都做不到。有人可以告诉我,如果Iam做错了或我应该添加什么。 Iam不是刚刚接触这方面的专家,而是尝试学习。

非常感谢提前家伙。

回答

0

你应该submittion时链接反馈和用户,插入到您还需要插入到用户信息表,如果用户在

$sql= "INSERT INTO feedback 
     (feedbacktitle, name, email, comment, datetime) 
     VALUES('$feedbacktitle', '$name', '$email', '$comment', '$datetime')"; 
$result = mysql_query($sql); 
if($result) { 
    $feedbackid = mysql_insert_id(); 
    if(isset($_SESSION['userid']) && $_SESSION['loggedin']) { 
     $uid = $_SESSION['userid']; 
     $uinfo_sql = "INSERT INTO user-info 
     (feedbackid, userid) 
     VALUES('$feedbackid','$uid')"; 
     $uinfoResult = mysql_query($uinfo_sql); 
     //etc etc 
    }  
} 
+0

岳Belegu记录反馈表后,我真的很无语。我花了两天的时间阅读和寻找答案,尝试了不同的解决方案,但无法得到它。 非常感谢,愿上帝保佑你兄弟。^_ ^ – Nassr