joebudden Posted January 8, 2007 Share Posted January 8, 2007 Hi, ive written an application that allows employees to upload files into a database.I am trying to implement code to stop the user from going beyond their database quota and thus have written this code[code]// does the file exceed that users file storage limit $fsize = $_FILES['frmFile']['size'];$fcurrent = $result['total'];$totals = $fsize + $fcurrent;if ($totals >= 1000000){ echo "Error, this file will exceed your total file size allowance"; echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>"; return; //a return here terminates the execution of this page.}/code]This works fine, however I need to use the value from the database (i.e. each employee can have a different quota)[code]//query to select dbEmployeeQuota $query2 = "select dbEmployeeQuota as quota from employee where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'"; $equota = mysql_query($query2);$a = mysql_fetch_array($equota, MYSQL_ASSOC);$quota = $a['quota'];[/code]This gets the quota out of the database and when i [code]echo $quota;[/code] it displays 1000000.Unfortunately when i try to use it in the IF statement..........[code]if ($totals >= $quota)[/code]OR[code]if ($totals >= $quota = $a['quota'])[/code]..........it still allows the file to be uploaded.If anyone can help me it would be highly appreciated ;D ;D ;DCheers guys[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/ Share on other sites More sharing options...
HuggieBear Posted January 8, 2007 Share Posted January 8, 2007 Maybe php doesn't like the data types. You could try this:[code]<?php// Get the limit from the database$query = "SELECT dbEmployeeQuota AS quota, dbEmployeeCurrent AS current FROM employee WHERE dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";$equota = mysql_query($query);$row = mysql_fetch_array($equota, MYSQL_ASSOC);$quota = intval($row['quota']);$current = intval($row['current']);// does the file exceed that users file storage limit $fsize = intval($_FILES['frmFile']['size']);if (($fsize + $current) >= $quota){ echo "Error, this file will exceed your total file size echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>"; return; //a return here terminates the execution of this page.}?>[/code]Notice that I've included the current quota in the sql query to the database, as I'm assuming this is where you're storing the information. You just need to alter the column name to the one in your db tableRegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155870 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 The second line isn't valid afaik.Is totals set? echo it to make sure? Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155871 Share on other sites More sharing options...
joebudden Posted January 8, 2007 Author Share Posted January 8, 2007 there is no column "dbEmployeeCurrent" ---- Huggieand jesirose --- it must be set coz it works with [code]$fsize = $_FILES['frmFile']['size'];$fcurrent = $result['total'];$totals = $fsize + $fcurrent;if ($totals >= 1000000)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155883 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 At the time of the if statement, you haven't defined $quota. Is your code out of order or something? Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155884 Share on other sites More sharing options...
joebudden Posted January 8, 2007 Author Share Posted January 8, 2007 il review it now, il repost in a minute we've just been chucked out of this lab !!!!brb Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155887 Share on other sites More sharing options...
HuggieBear Posted January 8, 2007 Share Posted January 8, 2007 [quote author=joebudden link=topic=121527.msg499842#msg499842 date=1168272220]there is no column "dbEmployeeCurrent" ---- Huggie[/quote]No, but if you want to check if a user is going over their quota, you must have the running total of what they're using stored somewhere right?Huggie Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155889 Share on other sites More sharing options...
joebudden Posted January 8, 2007 Author Share Posted January 8, 2007 hi, im back!!!I see what ur sayin Huggie, but cant this just be done on the page???Here is my code jesi[code]<?php// is there an uploaded file to insert? if (isset($_FILES['frmFile'])) { //query to calculate the total size of files in the database $query = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'"; $allowance = mysql_query($query); $result = mysql_fetch_array($allowance, MYSQL_ASSOC); // does the file exceed that users file storage limit $fsize = $_FILES['frmFile']['size']; $fcurrent = $result['total']; $totals = $fsize + $fcurrent; //query to select dbEmployeeQuota $query2 = "select dbEmployeeQuota as quota from employee where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'"; $equota = mysql_query($query2); $a = mysql_fetch_array($equota, MYSQL_ASSOC); $quota = $a['quota']; echo $quota; if ($totals >= $quota) { echo "Error, this file will exceed your total file size allowance"; echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>"; return; //a return here terminates the execution of this page. }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155900 Share on other sites More sharing options...
HuggieBear Posted January 8, 2007 Share Posted January 8, 2007 [quote author=joebudden link=topic=121527.msg499859#msg499859 date=1168273172]I see what ur sayin Huggie, but cant this just be done on the page???[/quote]Now you've posted your code, I can see you're using sum() to get the total size currently in use, so just use the code that I provided, only select one column, not the second one that I added.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155906 Share on other sites More sharing options...
joebudden Posted January 8, 2007 Author Share Posted January 8, 2007 cheers for the help you guys but once again i must relinquish my dignity.....after constructing a test page, i noticed that the value in my dbEmployeeQuota was 10mb and not 1mb, hence no errormy original code works fineLOVE U HUGGIE AND JES!!!!!!!!! PLEASE DONT BAN ME FOR MY STUPIDITY!!!!!!![code]<?php// is there an uploaded file to insert? if (isset($_FILES['frmFile'])) { //query to calculate the total size of files in the database $query = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'"; //query to select dbEmployeeQuota $query2 = "select sum(dbEmployeeQuota) as quota from employee where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'"; $allowance = mysql_query($query); $equota = mysql_query($query2); $result = mysql_fetch_array($allowance, MYSQL_ASSOC); $a = mysql_fetch_array($equota, MYSQL_ASSOC); // does the file exceed that users file storage limit $fsize = $_FILES['frmFile']['size']; $fcurrent = $result['total']; $totals = $fsize + $fcurrent; $quota = $a['quota']; if ($totals >= $quota) { echo "Error, this file will exceed your total file size allowance"; echo "<p>" . '<a href="viewuploads.php">' . "View Uploads" . "</a></p>"; return; //a return here terminates the execution of this page. }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33356-solved-problem-with-database-variable/#findComment-155925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.