Jump to content

endouken

Members
  • Posts

    48
  • Joined

  • Last visited

    Never

Everything posted by endouken

  1. That's not a great idea if i read it correctly - different months have different seconds, as do years. May seem punitive, but when a whole companies membership is out by a day it will be a very real problem. What seems to be being looked over in the "store a start and end date" response, is to calculate the end date i need to know the interval between the two, that interval needs be assumed somewhere - and all assumptions should be made in the database, this way a different value can be put in to the database and the php spits out a new answer without any modification; this is database design 101. How can i store "+1 year" in my database - would a varchar work? Then i can do (e.g.) $interval = GET duration from table products where productid = $productid and use that in the php date + $interval rather than date +1 year... Thanks for everyones replies so far, i did have a convo with Pikachu about this, which shed some light - but i'm always keen to debate and pick more brains! Tom.
  2. Perfect, missing that damned strtotime - many thanks! *bows down to your greatness*
  3. Thanks. That Echoed: So almost worked. I know the $_SESSION['date'] is OK - as underneath i have echo $_SESSION['date'] just to check... Any further thoughts? Thanks!
  4. Hey guys & gals, i have the following code: <?php $date= $_SESSION['date']; echo $date; ?> Which is an echo of an earlier page: <?php $_SESSION['date'] = date("c")?>; How do i format the echo of the first quote code? At present it echo's like so... ...which although is useful for back office purposes, not so easy on the eye for the customer. How can i format so it's like DATE-MONTH-YEAR? I have googled this and there are examples, but none for when echoing a $_SESSION which is where i'm falling flat on my face. I tried this: but it doesn't work :-( echo $startdate ("F j, Y") Thanks in advance to all who read and reply
  5. Perfect - thanks! I believe i miss-understood (down to lack of experience i admit - been doing php for 1-2 weeks now) The Little Guy's response - but your explanation goes further, far enough for me to grasp what you (and probably he originally) meant. In which case I am happy to admit you were partially correct - i did receive the response required, i just didn't realize it! So i've currently got a start and end date in my database, but i have "+1 year" in my php code. You mentioned using a variable to store the interval, could i just: - store a varchar of "+ 1 year" in a 'duration' column in my db, then - get this in my php code (pseudo: $duration = select duration from products where productid = $productid ) - make the end date calculation (pseudo: strtotime(date("F j, Y", strtotime($todayDate)) . "+$duration"); - and then insert it into the purchasehistory table. That way all the assumptions are in the database, or is this method unsuitable? Is there another (better) method of storing the +1 year variable? Have i got completely the wrong end of the stick?! Really appreciate you taking the time to reply - an honest thanks Tom.
  6. I got two responses - one from optikalefx who suggest what i've done - but this is not the correct/best way of calculating memberships based products for the reason I've stated above. The other response from The Little Guy suggested i use the MySQL date_sub() - i responded asking a follow up question as it seemed to me the end date was still being calculated using an assumption in php rather than an assumption in mysql. I received no reply back from The Little Guy so ergo i got no satisfactory response. There are two satisfactory responses: 1) confirmation that mysql cannot store a duration, or 2) confirmation that mysql can store a duration along with the method. "What i want to hear" bears absolutely no relevance to my perception of a satisfactory answer. If you look back over that thread, you will see neither 1) or 2) were garnered and instead i was (i believe) presented with two php based methods, which although leans towards conclusion #1 does not confirm it. Perhaps if you know the answer, you could let me know as i realize you have much more experience than I or even most on here? Also, i would like to point out i have been polite and courteous to all on here, despite the anonymity that internet forums provide. I realize you probably speak to many irritating and rude people on here, but I hope you do not judge me as one of these based on a my brief posting history. Maybe i need to post more to earn your respect, but that frankly seems like floored logic when deciding who you are and are not polite to. I did appreciate your earlier response however and my thanks to you was, and still is, genuine. Rgrds,
  7. Fixed! I commented out the line and redirected back to the form using a header command at line 64 header ('Location: http://www.mysite'); And all seems to be working. Is what I've done OK? Thanks again for your help - let me know that email address Tom. PS - don't suppose you know the answer to "what mysql datatype is best for storing intervals" - i asked this in the mysql section of phpfreaks and didn't get any satisfactory responses. Currently I calculate the renewal date of the product in php, but if i want to add a different product with a different renewal date i would need to start messing around with php code - where ideally i want to reference todays date and add a duration to it which is assumed in the productdetails table...but it looks like mysql can only store dates, not a duration of time. And as there are different seconds in each month/year i can't use the integer datatype...
  8. I will happily donate some money for a few drinks to a PayPal account - no jokes, you've been of unparalleled help - just let me know the email address (That's not against forum rules is it...?) This is working, but is throwing up a minor bug. The below error message is displayed... ...triggered by: - Entering a valid code - the screen changes to this error message (at mysite/discoutncode.php) and stops. Hitting the back button returns to the previous page with the price changed successfully. So it works, but with an odd error message. - Enter an invalid code - the java error message displays and as soon as OK is clicked the website flashes to the above error page before going straight back to the previous page automatically with the price unchanged. So it works, but there's an odd flash of that error message. - Enter a code with 0 uses left - same as above: entering an invalid code. - Blank code - same as above: entering an invalid code. Worth noting a different/the correct java message is shown for 2, 3 and 4. Is it safe to just delete this line as it's undefined - or is there a bit missing from the code? Thanks! Tom.
  9. Thanks for replying Pikachu. Unfortunately that's not had any impact. It's as if the code is simply ignoring this element of the code, and processing the discount regardless of whether the 'uses' remaining is 0 or 2...
  10. Heya. If you could help with a super kick butt one that would be awesome - i'm busy with the rest of the shopping cart process which i must admit is a hell of a lot easier than the discount engine you wrote! Chat laterz Tom.
  11. Cant edit my above post, Might be worth mentioning that i've also noticed the following - which may help diagnose the problem: - When the input box is blank the java error message is displayed correctly on submit, however when an incorrect code is entered the error message is not displayed - it runs the scripts and the price doesn't change (so it works OK....but it doesn't show the 'if false' java error response other than on a blank submit) - i tried flipping the < and > signs to see what error it would throw up...however using the below code, both codes were accepted regardless of which < or > sign was used... if (($dcode = $uniquecode) && ($uses <= 0)) { Perhaps food for thought...
  12. Heya, I don't know how to respond to that - other than i wish him and you well. Apologies i fell asleep last night - 4:30am over here when i sent my last message Still not working - just rejects both codes. I can re-assure you the mysql side of it is set up correctly, i've phpmyadmin as well as mysql workbench which both confirm the values for the two codes uses are 0 and 2 respectively. I look forward to hearing from you in due course, thank you for your help and patience. Tom.
  13. Hmmm, it's still rejecting both codes (still with one code with 2 uses, the other has 0). It was working 50% before, subtracting -1 from the uses column - but it was also accepting a code with 0/zero uses remaining and then subtracting -1 so the codes remaining uses ran into negatives. Code we were using when this was happening was: if (($dcode = $uniquecode) && ($uses <= 2)) {
  14. Made the changes to php and the database, and now it's rejecting both codes (one code has 2 uses, the other has 0). Where you say: What does the exclamation mark mean in $uses != 0, and where did we say in php they have 2 uses - or did you simply mean via mysql we would specify this? Appreciate the perseverance and the tutorship! Tom.
  15. <?php session_start(); $localhost="00.000.000.00"; $username="###"; $password="###"; $database="mfirst"; mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Clean up the code the user entered $uniquecode = mysql_real_escape_string($_POST['discountcode']); // OR whatever the name of the input is $discountcodecheck = mysql_query("SELECT uniquecode, discount FROM discounttable WHERE uniquecode = '".$uniquecode."'"); $row = mysql_fetch_array($discountcodecheck, MYSQL_BOTH); // MYSQL_BOTH incase it's alphanumeric, and establish the $row array with the codes $dcode = $row['uniquecode']; $remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."'"); $row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses $uses = $row1['uses']; // Check the code vr the code the user entered, and let's make sure the user hasn't used it over 2 uses if (($dcode = $uniquecode) && ($uses <= 0)) { // Since they check out we can do our discount $discount = ($_SESSION['sessionprice'] - $row['discount']); $adduse = mysql_query("UPDATE discounttable SET uses=uses-1 WHERE uniquecode = '".$uniquecode."'"); $_SESSION['sessionprice'] = $discount; } else { // Let them know the code or the uses have been reached, you could seperate the if statement above to give an error for uses ?><script type="text/javascript"> alert("Discount Code Entered Is Either Not Valid Or Has Been Previously Used."); history.back(); </script><?php } // close our if for checking the code and the uses mysql_close(); ?>
  16. Not quite working still - just rejects both the code with negative uses and the code with 90 uses (i changed <=2 to <=99) $row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses $uses = $row1['uses']; Will the problem lie here? as we're saying uses = $row1, however we're not specifying uses anywhere in $row1...i dunno? I may need to sleep on it :-) Cheers again buddy, Tom.
  17. You are awesome and deserve a medal - you have effectively built me a discount code engine The final bug ("just one more thing" - like columbo if you watch it) is that... if (($dcode = $uniquecode) && ($uses <= 2)) { ...is accepting a test code which has '0' zero uses remaining. In fact, now it has minus 2 uses remaining! lol. I believe this is the last bug to iron out - you've been a great help and i've genuinely learnt more in the last few hours than i have in a long while. Tom.
  18. Awesome, Which is correct as the test discount code was 39.00. I can't see (though i may be wrong) the code which is then updating $_SESSION['sessionprice'] with this new price - how do we add this? I tried simply deleting the echo, and the screen just refreshes but the price doesnt change - so i'm assuming the $_SESSION['sessionprice'] hasn't been updated as it's echoing correctly when that line of code is included. Finally, i also have a 'uses' column (which we checked earlier in the if statement)...how do we 'minus one' from this column once it's been searched? Otherwise the code would have infinite uses Thanks for all your help! Tom.
  19. Yeh - i changed that, the amended code is: $discount = $_SESSION['sessionprice'] - $row['discount'] (my amended code) $discount = $_SESSION['sessionprice'] - $row['discountamt']; (your original code - replaced by the above line) So our naming logic is very similar! However, this is not the issue. The column is a decimal, as that's supposed to be the 'best' data type in MYSQL for monetary values - if that makes a difference? If not, what else could it be? I've read and re-read your code and it makes sense to me, but it's just not doing that final calculation. The 'false' part works a-ok and I've customized that so it falls in line with how the rest of the error messages have been previously displayed. I'm determined to get this before i go to sleep! Thanks again, Tom.
  20. Thanks for your kindness. Sweet - it's almost working, so close now i can taste it. (It was me being a dumb *** - your instinct as to the cause of the error was dead on. Sometimes i surprise myself with utter stupidity). No errors now, but the successful 'if' doesn't seem to alter the session price, it still displays the original full price after a valid discount code is entered. I added the "echo $discount;" line and sure enough it shows the full price - what's not happening with the calculation? Thanks buddy Tom.
  21. Thanks. Error message now changed to many many more: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 9 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 9 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 11 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 11 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 12 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 16 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 16 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 17 Sorry but you've used twice already. Warning: Cannot modify header information - headers already sent by (output started at D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php:9) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 40 Warning: mysql_close(): no MySQL-Link resource supplied in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 42 I feel bad continually asking for help - but do appreciate it
  22. Thanks - I feel like i owe you a drink with this help :intoxicated: I get the following error: What does a T_boolean_and error mean? Not sure how to correct this as i don't understand the error... Thanks again, Tom.
  23. Thanks for taking the time to reply. How do i 'dump' this information? (i'm new to php but not to coding so i'm a very quick study). How do i combine this with what i've already written? I've been looking at this code for the last half hour and simply do not know where to start in incorporating your code... Also this line: if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0)) seems to be ignoring if the 'uses' is > 0 when i try it out. I have a code with 0 uses and i still seems to accept it with the success message... I will secure once the code is working - but thanks for checking :-) Cheers, I really appreciate the support from you / the php freaks community. Tom.
  24. You Sir/Ma'am, are a gentleman/gentlewoman and a Saint Much appreciated. That's number 1) above solved, just two more to go! Thanks! Tom.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.