PHP - Checking Condition In Sql Query
Hi there,
I am working on a PHP website. And I am running a query which checks for the expired products. We check to see if the expiry date is greater than the current systems date then display the record. It looks something like this: Code: [Select] select * from products WHERE products.productExpiry) >= '2010-10-13 00:00:00' 'productExpiry' field is of 'Datetime' Datatype And Expiry date is stored in database as: 2010-10-19 04:39:35 Now it works fine. But the problem only arises (no record shows) when there is no date in the 'productExpiry' field. How can I check or set a condition in my SQL query that whenever the 'productExpiry' is Null or Blank don't compare it with the current date. Please reply All comments and feedbacks are welcomed Thank you! Similar TutorialsI have the following if statement: Code: [Select] if ((isset($select_category) == 'All') || (!isset($select_category)) && (!isset($most_liked))) { The value for the variable gets taken from a drop down menu, which is a list of categories. The problem I am having is with the isset condition check is that the variable is always set, but it does not consider the check for equality with the 'All' condition. Which basically means no matter which category I choose from the drop down menu, it always goes to this very first if statement, and does NOT go to the other elseif statement, and I think it has to do with the isset condition check, because without it it would work, though without it I am getting a notice warning, that the variables are undefined. Any ideas how I can make it check if its equal to 'All' together with the isset condition check? What I am trying to say is no matter which category is chosen, with the isset condition check, the variable is always set, thus the if statement is true, there basically seems to be a contradiction going on. I am trying to use the following query with sorting: $query = mysql_query("SELECT * FROM Table WHERE Date LIKE '$PeriodSelected' ORDER BY Date DESC"); $PeriodSelected is basically supposed to get me all results from month selected and it works fine. Now I am trying to add sorting to this query and although I get no errors it does not matter if I use ASC or DESC my results are sorted in the same way. Not sure what I am doing wrong. I'm a bit of a newb to PHP and MySQL. I seem to be having an issue with something. How do I loop through an array, querying each value in the array until the query meets a certain condition.. In this case it would be that the number of rows returned from the query is less than five. Here is what I have: $query1="SELECT UserID FROM Users where RefID='$userid'"; $result1=mysql_query($query1); while ($row = mysql_fetch_array($result1, MYSQL_NUM) && $sql2querynum < '5') { echo ($row[0]); echo " "; $sql2 = "SELECT * FROM Users WHERE RefID=$row[0]"; $sql2result = mysql_query($sql2); $sql2querynum = mysql_numrows($sql2result); } Problem is, for every value it echoes out, I get the following warning: mysql_numrows(): supplied argument is not a valid MySQL result resource Like I said, I'm a newbie to PHP to maybe I'm not even going about doing this the right way. Hoping someone can help to point me in the right direction. I have a query: $query ="select * FROM telephone_admin where name Like ' ".$_GET['answer']." ' "; I would like to add % before and after so that the query will search for result which contains the PHP variable $_GET['answer'] before or after, but the problem is how can I add % before or after ' ".$_GET['answer']." ' within the query?? Thanks! I don't know precisely how to put it so i will give an example: suppose you have a search form with input fields for: -an age range, -a data range, -for the sex, -postal code as soon as the user would fill in one of these input fields, a query should be generated including a condition doing something with the inputted value. For example, the user fills in maxAge, the the query should say: SELECT * FROM table WHERE age >= maxAge; Filling more than one criterion then would do .= " AND criteria (condition) inputvalue " etc... My question comes to the part about: how to check if there is already a WHERE in the clause and how to put WHERE or AND for every criterion. Since doing like above, i won't be able to search for another criterion if i don't select maxAge first because then there would be no WHERE in the sql clause. Hopefully i've put it clear thanks in advance Hello, I have a problem. I run this query: $query = "SELECT column1 FROM table WHERE column2='$kk'"; $which = $link1; mysql_query($query,$which); some codes.... It is displaying all data correct but only when $kk exists in column2 and when $kk does not exist, it display blank page. So, i want to do a check before running above query to make sure that $kk exists in column2. How to check it before running query? In an .html, before : <!-- BEGIN myquery --> I need to stop output and check the content of "myquery" Is there a command for that ? Thank You. I have this if statement with validations and mysql query Code: [Select] <?php if(isset($_POST['submit'])) { $errors = array(); $required_fields = array('menu_name', 'position', 'visible'); foreach($required_fields as $fieldname) { if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { $errors[] = $fieldname; } } $fields_with_length = array('menu_name' => 30); foreach($fields_with_length as $fieldname => $maxlength) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } if(empty($errors)) { //Perform Update $id = mysql_prep($_GET['subj']); $menu_name = mysql_prep($_POST['menu_name']); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible} WHERE id = {$id}"; $result = mysql_query($query, $connection); if(mysql_affected_rows() == 1) { //success $message = "Record has been successfuly updated!"; } else { //failed $message = "The subject update failed"; $message .= "<br>". mysql_error(); } } else { //Error Occured $message = "There were ". count($errors) . " error in the form"; } } ?> I'm having problem on this line Code: [Select] <?php if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) ?> this line is for validation of my radio button which has a 0 and 1 value. Quote && $_POST[$fieldname] != 0 Eventhough the textbox is not set and is empty, it's still bypassing my if statement and still executing the update query... Can someone please tell me what i have got wrong here? I am trying to return value C if conditions a AND B are met or return value D. Not sure if its parenthesis or something else? <?php if (($row_Recordset4['multidirection']=="yes") && ($_POST["widthcheck"] < $row_Recordset4['drop'])) echo $row_Recordset4['width'];else echo $row_Recordset4['drop'] ?> Thanks if u use this for one condition if ($nr > 5) how would u check if the nr is between 5 and 50 thanks ! Code: [Select] if($this->color=="Blue" || $this->color=="Green" || $this->color=="Red" || $this->color=="Yellow") { return true; } else { return false; } This is returning false, when it should be returning true because $this->color DOES equal "Red"... I can NEVER EVER get these conditional things to work UNLESS it's &&, but I even tried: !$this->color != "Red" && ......... as well to see if that would work even though that's really confusing. Can someone help me finally understand this stupid OR stuff? Hi.. I tried this code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); mysql_select_db("mes", $con); if (!$con) { echo 'failed'; die(); } $sql = "SELECT PCODE, total FROM kanban_checker ORDER BY PCODE"; $res = mysql_query($sql, $con) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $PCODE = $row['PCODE']; $total = $row['total']; } $sql = "SELECT P28, P28_max, P28_min, P30, P30_max, P30_min, P32, P32_max, P32_min, P33, P33_max, P33_min, P35, P35_max, P35_min, P35M, P35M_max, P35M_min, P35W, P35W_max, P35W_min, P38, P38_max, P38_min, P41, P41_max, P41_min, P42, P42_max, P42_min, P43, P43_max, P43_min, P46, P46_max, P46_min FROM parameter_settings"; $res_pcode = mysql_query($sql, $con); $row = mysql_fetch_assoc($res_pcode); $P28 = $row['P28']; $P28_max = $row['P28_max']; $P28_min = $row['P28_min']; $P30 = $row['P30']; $P30_max = $row['P30_max']; $P30_min = $row['P30_min']; $P32 = $row['P32']; $P32_max = $row['P32_max']; $P32_min = $row['P32_min']; $P33 = $row['P33']; $P33_max = $row['P33_max']; $P33_min = $row['P33_min']; $P35 = $row['P35']; $P35_max = $row['P35_max']; $P35_min = $row['P35_min']; $P35M = $row['P35M']; $P35M_max = $row['P35M_max']; $P35M_min = $row['P35M_min']; $P35W = $row['P35W']; $P35W_max = $row['P35W_max']; $P35W_min = $row['P35W_min']; $P38 = $row['P38']; $P38_max = $row['P38_max']; $P38_min = $row['P38_min']; $P41 = $row['P41']; $P41_max = $row['P41_max']; $P41_min = $row['P41_min']; $P42 = $row['P42']; $P42_max = $row['P42_max']; $P42_min = $row['P42_min']; $P43 = $row['P43']; $P43_max = $row['P43_max']; $P43_min = $row['P43_min']; $P46 = $row['P46']; $P46_max = $row['P46_max']; $P46_min = $row['P46_min']; $P47 = $row['P47']; $P47_max = $row['P47_max']; $P47_min = $row['P47_min']; if($PCODE = $P28 || $total = $P28_min){ echo $P28_min; } elseif($PCODE = $P30 || $total = $P30_min){ echo $P30_min; } elseif($PCODE = $P32 || $total = $P32_min){ echo $P32_min; } elseif($PCODE = $P33 || $total = $P33_min){ echo $P33_min; } elseif($PCODE = $P35 || $total = $P35_min){ echo $P35_min; } elseif($PCODE = $P35M || $total = $P35M_min){ echo $P35M_min; } elseif($PCODE = $P35W || $total = $P35W_min){ echo $P35W_min; } elseif($PCODE = $P38 || $total = $P38_min){ echo $P38_min; } elseif($PCODE = $P41 || $total = $P41_min){ echo $P41_min; } elseif($PCODE = $P42 || $total = $P42_min){ echo $P42_min; } elseif($PCODE = $P43 || $total = $P43_min){ echo $P43_min; } elseif($PCODE = $P46 || $total = $P46_min){ echo $P46_min; } elseif($PCODE = $P47 || $total = $P47_min){ echo $P47_min; } else{ echo ''; } ?> for display data if total = min. The problem is, in this condition he satisfied if condition even though $total is not equal to $P28_min. Thank you this code works fine if the conditions are absolute ( pass, fail or empty). im trying to make the fail work if its part of the query. ive tried %fail% but didnt work. $choice = strtoupper($rows['comments']); if($choice == "PASS"){ $bgc = "#ff25f0" ; } elseif($choice == "FAIL"){ $bgc = "#666666" ; }else{ $bgc = "#FF6600" ; } <?php $id1 = '5' ; $id = array(1,2,3,4,5,6,7); foreach($id as $value){ if($id1==$value){ echo 'One of them matches, ' ; echo 'Do not execute command <BR>' ; } ////// if ends here } ////// loop ends here ?> How to do something if all statements are false ? like when id $id1 = '10' , ? Hi.. I have form for leave and now I need to add checkbox for halfday. if checkbox is checked the HOURS_LEAVE = HOURS_LEAVE * 4 because his leave is halfday only. then if checkbox is not check the HOURS_LEAVE = HOURS_LEAVE * 8 . and also if checkbox is check the value is H else W then it also save to database here is my code for LeaveEmp.php <?php include 'config.php'; date_default_timezone_set('Asia/Singapore'); session_start(); $currentEmpID = $_SESSION['empID']; $EMP_NO = $_GET['EMP_NO']; $NAME = $_GET['NAME']; $DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO']; $HOURS_LEAVE = $_GET['HOURS_LEAVE']; $Approve = $_GET['Approve']; $TYPE =$_GET['TYPE']; $dateprocess = $_GET['dateprocess']; $DATE_LEAVE = $_GET['DATE_LEAVE']; $EMPNO = $_GET['EMPNO']; function GetDays($StartDate, $EndDate){ $StartDate = date("Y-m-d", strtotime($StartDate)); $EndDate = date("Y-m-d", strtotime($EndDate)); $Days[] = $StartDate; $CurrentDate = $StartDate; while($CurrentDate < $EndDate){ $CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate))); if(date("w",strtotime($CurrentDate))>0){ $Days[] = $CurrentDate; } } return count($Days); } $HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO); $smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday')); $smarty->assign('TYPE', $TYPE); $sql = "SELECT l.EMP_NO, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND em.EMP_ID = '$currentEmpID' AND l.DATE_LEAVE_FROM = '$DATE_LEAVE_FROM'"; $result_edit = $conn2->Execute($sql); $DATE_LEAVE_FROM = $result_edit->fields['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $result_edit->fields['DATE_LEAVE_TO']; $smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM); $smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO); $sql = "SELECT l.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.PERSONAL p, $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND p.EMP_ID = em.EMP_ID ORDER BY FULLNAME"; $rs = $conn2->GetAll($sql); $smarty->assign('getleave', $rs); $smarty->display('header_att.tpl'); $smarty->display('LeaveForm.tpl'); $smarty->display('footer.tpl'); ?> here is my code for saving leave: <?php include 'config.php'; date_default_timezone_set('Asia/Singapore'); $currentEmpID = $_SESSION["empID"]; $EMP_NO = $_GET['EMP_NO']; $NAME = $_GET['NAME']; $DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO']; $HOURS_LEAVE = $_GET['HOURS_LEAVE']; $TYPE =$_GET['TYPE']; $Approve = $_GET['Approve']; $dateprocess = $_GET['dateprocess']; $today = date("Y-m-d"); function GetDays($StartDate, $EndDate){ $StartDate = date("Y-m-d", strtotime($StartDate)); $EndDate = date("Y-m-d", strtotime($EndDate)); $Days[] = $StartDate; $CurrentDate = $StartDate; while($CurrentDate < $EndDate){ $CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate))); if(date("w",strtotime($CurrentDate))>0){ $Days[] = $CurrentDate; } } return count($Days); } $HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO); $HOURS_LEAVE = $HOURS_LEAVE * 8; $smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday')); $smarty->assign('TYPE', $TYPE); $smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM); $smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO); $smarty->assign('EMP_NO', $EMP_NO); $smarty->assign('NAME', $NAME); $smarty->assign('HOURS_LEAVE', $HOURS_LEAVE); $smarty->assign('TYPE', $TYPE); $smarty->assign('dateprocess', $today); $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeave = $conn2->Execute($sql); $numrowsRsLeave = $RsLeave->RecordCount(); if($numrowsRsLeave > 0){ echo "<script>alert('Transaction has already been process')</script>"; echo "<script>navigate('LeaveEmp.php')</script>"; } else { $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeave = $conn2->Execute($sql); $saverec['EMP_NO'] = $EMP_NO; $saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM; $saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO; $saverec['HOURS_LEAVE'] = $HOURS_LEAVE; $saverec['TYPE_LEAVE'] = $TYPE; $saverec['STATUS_LEAVE'] = $Approve; $saverec['DATE_PROCESS'] = $today; $insertSQL = $conn2->GetInsertSQL($RsLeave, $saverec); $conn2->Execute($insertSQL); } $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeaveLog = $conn2->Execute($sql); $numrowsRsLeave = $RsLeaveLog->RecordCount(); if($numrowsRsLeave > 0){ echo "<script>alert('Transaction has already been process')</script>"; echo "<script>navigate('LeaveEmp.php')</script>"; } else{ $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeaveLog = $conn2->Execute($sql); $saverec['EMP_NO'] = $EMP_NO; $saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM; $saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO; $saverec['HOURS_LEAVE'] = $HOURS_LEAVE; $saverec['TYPE_LEAVE'] = $TYPE; $saverec['STATUS_LEAVE'] = $Approve; $saverec['DATE_PROCESS'] = $today; $insertSQL = $conn2->GetInsertSQL($RsLeaveLog, $saverec); $conn2->Execute($insertSQL); } session_write_close(); header("Location:LeaveEmp.php"); exit(); ?> And here is the LeaveForm.tpl <script> window.onload = function() { var ul = document.getElementById('searchpayroll'); var links = ul.getElementsByTagName('a'); var i = 0; document.onkeyup = function(e){ e = window.event || e; var key = e.charCode || e.keyCode; if (key == 40) { if (i < links.length - 1) i++; links[i].focus(); } else if (key == 38) { if (i > 0) i--; links[i].focus(); } } } function ApproveLeaveOP(){ var EMP_NO = document.getElementById('EMP_NO').value; var DATE_LEAVE_FROM = document.getElementById('DATE_LEAVE_FROM').value; var DATE_LEAVE_TO = document.getElementById('DATE_LEAVE_TO').value; var NAME = document.getElementById('NAME').value; var HOURS_LEAVE = document.getElementById('HOURS_LEAVE').value; var Approve = document.getElementById('Approve').value; var TYPE = document.getElementById('TYPE').value; var dateprocess = document.getElementById('dateprocess').value; var H = document.getElementById('H').value; document.sampleform.action="AddLeave.php?EMP_NO="+EMP_NO+"&DATE_LEAVE_FROM="+DATE_LEAVE_FROM+"&DATE_LEAVE_TO="+DATE_LEAVE_TO+"&NAME="+NAME+"&HOURS_LEAVE="+HOURS_LEAVE+"&Approve="+Approve+"&TYPE="+TYPE+"&dateprocess="+dateprocess+"&H="+H; document.sampleform.submit(); } </script> <script type="text/javascript" src="op_from_date_leave.js"> </script> <script type="text/javascript" src="op_from_date_leave_conf2.js"></script> <div id="Search"> <form> <p class="serif"><b>Search Lastname:</b></p> <input type="text" name="search_" size="20" onkeyup="searchEmpLeaveOP(this.value);"> <div> <hr /> <ul id="searchpayroll" style="overflow:auto; height:380px; width:100%; margin-left:2px;"> {section name=co_emp loop=$personalAll} <li><a href="LeaveData.php?queryEmpID={$personalAll[co_emp].EMP_ID}">{$personalAll[co_emp].FULLNAME}</a></li> <hr /> {sectionelse} <li>No records found</li> {/section} </ul> </div> <div id="EmpOTForm"> <fieldset> <legend>Overtime and Leave Form</legend> <input type="button" name="OTbtn" value="Overtime" onclick="OtFrmOP()")> <input type="button" name="Leavebtn" value="Leave" onClick="LeaveOP()"> <p class="serif"> <label id="LeaveEmpIDLabel">EMP ID</label><label id="LeaveNameLabel">NAME</label><label id="FromLeave"><a href="Javascript:showCal('RegCalendar1')">FROM DATE </a></label><label id="DaysLabel"><a href="Javascript:showCal('RegCalendar2')">TO DATE</a></label><label id="TypeLeave">LEAVE TYPE</label><label id="HLeave">H</label> <input type="text" name="EMP_NO" id="EMP_NO" value="{$empno}" size="8" > <input type="text" name="NAME" id="NAME" value="{$fullname}" size="35" > <input type="text" name="DATE_LEAVE_FROM" id="DATE_LEAVE_FROM" value="{$DATE_LEAVE_FROM}" size="9"> <input type="text" name="DATE_LEAVE_TO" id="DATE_LEAVE_TO" value="{$DATE_LEAVE_TO}" size="9"> {html_options id=TYPE name=TYPE options=$LeaveStatus selected=$TYPE style="width:140px;"} <input type="checkbox" name="H" id="H" value=""> <input type="button" name="Approve" value="Approve" id="Approve" onclick="ApproveLeaveOP()"> <input type="button" name="Edit" value="Edit" id="Edit" onclick="EditLeaveOP()"> <input type="hidden" name="dateprocess" id="dateprocess" value="{$dateprocess}"> </p> <input type="hidden" id="HOURS_LEAVE"> </fieldset> <div> <p> <table border="1" class="stat" width="auto"> <tr> <th>EMP ID</th> <th>NAME</th> <th>FROM DATE</th> <th>TO DATE</th> <th># of HOURS</th> <th>TYPE</th> <th>STATUS</th> </tr> {section name=att loop=$getleave} <tr> <td id = "EMPNO">{$getleave[att].EMP_NO}</td> <td >{$getleave[att].FULLNAME}</td> <td id = "DATE_LEAVE" onclick="opleave_edit('{$getleave[att].DATE_LEAVE_FROM}')">{$getleave[att].DATE_LEAVE_FROM}</td> <td >{$getleave[att].DATE_LEAVE_TO}</td> <td >{$getleave[att].HOURS_LEAVE}</td> <td >{$getleave[att].TYPE_LEAVE}</td> <td >{$getleave[att].STATUS_LEAVE}</td> </tr> {/section} </table> </p> </form> </div> </div> </div> I attach the sample form. Thank you Hello, I am making a full backup of cPanel account. It takes few seconds for zipping 4 to 10 MB of data but when there are more than 200 MB of data on cpanel account, obviously it will take some more time, say for example 2 minutes. On cpanel based servers, while zipping, it temporarily creates a ZIP file of 33KB And this file's size stays at 33KB until the process get completed i.e. till it completes a backup file So conditionCHK is >> If example.zip > 33KB then, backup ZIP file is ready else sleep(15) and check conditionCHK again Point is that, it should check condition again and again until it satisfy. So in my case, it script will check again and again whether example.zip has become more than 33KB or not. If it not, then sleep for 15 seconds and again check Once condition will satisfy, it will show "Success" Which loop can I use here ? I am totally confused in developing a logic. Thanks. I'm having trouble with a script and I just can't figure out what's wrong with it. The script is located at http://www.qlhosting.com/ham/check.php Here's the code for it <?php if (isset($_POST['submit'])) { $domain = $_POST['domain']; $password = md5($_POST['password']); include 'db.php'; mysql_query("SELECT * FROM apps WHERE domain='$domain' AND WHERE cpassmd5='$password' LIMIT 1"); $stat = $row['status']; } else { } ?> <!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>Quotaless Web Hosting | Check Status</title> <style type="text/css"> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } </style> </head> <body> <h1>Check Application/Account Status</h1> <?php if ($stat="PENDING") { echo "<hr />"; echo "Your application is currently listed as PENDING. Our staff have not viewed your application yet. Please be patient, and watch your email for a response. Thank you!"; } elseif ($stat="NMI") { echo "<hr />"; echo "We need more information from you in order to take action on your application. Please check your e-mail inbox for a message from our staff specifically stating what we need. If you did not get this message, please post a message on our support forum. Thank you!"; } else { } ?> <hr /> <h2>To check the status of your application or account, login using the form below.</h2> <form id="check" name="check" method="post" action="<?php echo $PHP_SELF;?>"> <p>Domain: <input type="text" name="domain" id="domain" /> <br /> Password: <input type="password" name="password" id="password" /> <br /> <input type="submit" name="button" id="button" value="Check" /> </p> </form> <hr /> <p> </p> </body> </html> The part under if ($stat="PENDING") is performed upon page load, even when the if condition relating to it is false. I can't seem to figure out what exactly is wrong here. Please help me out. I would really appreciate the help. Thanks! Anthony Hi all.
In my database, i have a table where a client chose a service providers to make payments and each bill setup counts as a reward point for the client. Each bill counts as a single point even if the bill is edited after a services might have expired or renewed it should not be counted again as point.
to count the number of bill set up by a client i did
$stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 1 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute();Its okay if it counts for new bills but i want it not to count for the same service provide and so i did $stmt=$pdo->query("SELECT company FROM payment WHERE username = '$username' AND trans_ref = '$trans_ref'"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $coy = $row['company']; } //ps: note, $company is a variable from the form if(strcmp($coy, $company) == 0){ $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 0 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute(); }elseif(strcmp($coy, $company) != 0){ $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 1 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute(); }it just wont add up i also tried $coy1 = $coy; $coy2 = $company; $point = 0; if(strcmp($coy1, $coy2) == 0){ $add_point = $point + 0; }else{ $add_point = $point + 1; } $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = $add_point WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute();still wont work. any idea? |