Iam strugling with my issue to link user to his feedback he posted. I have feedback.php page and it is available for members and non-members to submit feedback to admin. I have a feature where if user login and send feedback while he's loggedin, he will be able later-on to preview his feedbacks in his profile page.
I created 3 tables in my Dbase which are(user, feedback, user-info).
User tbale has: ('userid' ,'fname', 'lname', 'username', 'email', 'password') userid(pk)
feedback table has:('feedbackid' ,'feedbacktitle', 'name', 'email', 'comment', 'datetime') feedbackid (pk)
user-info table has: ('id', 'feedback-id', 'user-id') id(pk) feedback-id(fk) user-id(fk)
I tried to add (Fk) in user table and feedback table to display the user who sent the feedback but couldn't. and then I created the user-info in attempts to get what I want but no-thing.
This is my feedback.php page:
<?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>
And this is my 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>
That what I have. I tried a lot to solve and couldn't. can someone tell me if Iam doing wrong or what should I add. Iam not an expert just new to this and try to learn.
Thanks alot in advance guys.