Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding variables 1

Status
Not open for further replies.

d0nny

IS-IT--Management
Dec 18, 2005
278
GB
Ok, this has stumped me and I think I'm getting more and more confused the more I try to resolve it.

I'm running a check on a database table after a form submission - basically, I want to ensure that a user cannot enter more than 8 hours for a single date in a timesheeting system.
So I run a query on the database for the sum of hours for the userID and date. UserID is equal to the session uid and the date is the date input on the form.

This is what I have ...
Code:
$q_dupcheck = "select sum(hours) from ts_entry where user_id='$_SESSION[uid]' and date='$newdate'";
$dup_check = mysql_query($q_dupcheck);
$total_hours = $dup_check + $_POST['hours'];
if ($total_hours <= 8) {
    blah, blah, blah

Doesn't work! Obviously.
So, how do I get a numeric result from the database and add it to the number of hours posted?
 
doesn't work because mysql_query returns a resource not a result.

Code:
$q_dupcheck = "select sum(hours) [red]as c[/red] from ts_entry where user_id='$_SESSION[uid]' and date='$newdate'";
$dup_check = mysql_query($q_dupcheck);
[red]$row = mysql_fetch_assoc($dup_check);
if (  ($row['c'] + $_POST['hours']) > 8){
  echo 'you cannot work more than 8 hours on a day';
} else {
  echo 'something';
}
 
Fantastic !
Many thanks ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top