Hi,
I'm currently working on a support page. Right now, it successfully allows a user to type in a question, where the information is inserted into my database. With one flaw though.
There is a check that ensures the user doesn't have more than 3 questions at a time. I need to have this check for questions that also have a status "answered" set to 'no'.
For example: For every question that the user asks, the answered status is set to 'no' by default. If the user has more than 3 unanswered questions at any time, they won't be able to ask another question. If they have 5 questions they have asked though perhaps, but 4 are set to 'yes', and 1 is set to 'no, they will be able to ask a question.
What should I change to get this to work properly?
Thanks
<?php
session_start();
$username = $_SESSION['username'];
if(isset($_SESSION['username'])){
$submit = $_POST['submit'];
if($submit){
include_once('inc/connect.php');
$supportsql = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
$row = mysql_fetch_assoc($supportsql);
$userid = $row['id'];
$message = $_POST['problem'];
$date = date("Y-m-d");
$checksql = mysql_query("SELECT id FROM `support` WHERE `id`='$userid'");
$idcount = mysql_num_rows($checksql);
$checkmessage = mysql_query("SELECT message FROM `support` WHERE `message`='$message'");
$messagecount = mysql_num_rows($checkmessage);
// Fix this to take in account if the question has already been answered.
if ($idcount<=2){
if ($messagecount==0){
$supportquery = "INSERT INTO support VALUES ('','$userid','$username','$message','no','$date')";
$supportresult = mysql_query($supportquery) or die("Error Inputting Message");
}
else{
$error = "You have already submitted this question. It will be replied to within 24 hours.";
}
}
else{
$error = "Sorry, you currently have 3 Support Tickets awaiting to be answered.<br />Please wait until these are answered before asking another question.";
}
}
}
else{
header("Location: index.php");
}
?>
<html>
<head>
<title>Support</title>
</head>
<body OnLoad="document.support.problem.focus();">
<center>
<h1>Get Support!</h1>
<form name="support" action="support.php" method="POST">
<textarea rows="8" cols="50" name="problem"><?php echo $message; ?></textarea><br />
<input type="submit" name="submit" value="Submit">
</form>
<br />
<?php echo $error; ?>
</center>
</body>
</html>