Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Checking number of rows and checking status of row
Old 07-13-2010, 09:36 PM Checking number of rows and checking status of row
Skilled Talker

Posts: 83
Trades: 0
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 Code:
<?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>
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Checking number of rows and checking status of row
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08736 seconds with 12 queries