Jump to content

dshevnock

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by dshevnock

  1. I felt more comfortable using the if...elseif statements, so that is what I went with. I am definitely doing some form validation with Ajax to make the user experience a little bit better. If there are any error messages, the error message that is associated with the field appears below the form field. (And I am trying to learn Ajax so I thought this would be a good guniue pig for my learning.) I was going to have the user input the email address, then re-input it for verification sakes, but have since removed the second textbox to re-enter the password. Now that I am thinking about it though, I think I will end up putting the verification part back in. Here is the JavaScript that I came up with for just the e-mail entry field. function checkEmail(){ var objEmail = document.getElementById('email'); var varEmail = objEmail.value; if(varEmail != ""){ var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i; var returnval=emailfilter.test(varEmail); if (returnval==false){ document.getElementById('errorInvalidEmail').style.display = 'block'; objEmail.focus(); } else{ document.getElementById('errorInvalidEmail').style.display = 'none'; } return returnval; } else{ document.getElementById('errorInvalidEmail').style.display = 'none'; } }
  2. Is it better practice or more effecient to use nested TRY...CATCH statements as opposed to nested IF statements? The reason I ask is because I am trying to develop a signup form that allows a user to add his/her e-mail address (optional) with 2 textboxes in the form (email and verifiedEmail).
  3. Thanks Wildbug! That worked superbly!
  4. I don't have much experience writing mysql statements with IF statements. I did however come up with this one and wanted to know if this query was valid/make sense/logical/etc. SELECT sum( IF(pos.created_by= '8',1,0)) AS userOpenedTotalCount, sum( IF(pos.updated_by = '8' AND pos_details.closed = 'Y',1,0)) as userClosedTotalCount, sum( IF( pos.created_date BETWEEN '2007-07-02 00:00:00' AND '2007-07-02 23:59:59' AND pos.created_by = '8', 1, 0 ) ) AS userOpenedTodayCount, sum( IF( pos.last_updated_date BETWEEN '2007-07-02 00:00:00' AND '2007-07-02 23:59:59' AND pos.updated_by = '8' AND pos_details.closed = 'Y', 1, 0 ) ) AS userClosedTodayCount FROM pos JOIN pos_details ON pos.id = pos_details.id Or is there a better way to write this?
  5. Awesome! Thanks everyone. You all have been a huge help!
  6. What do the 2 extra options after 'Y' or 'N' in IF (active = 'Y', 1, 0) mean?
  7. The active field is set to a 1 CHAR not null field (I use Y or N). When the card number is initially added to the database (when we first get the cards from our printer), the "active" field is set to N. Then when the customer receives card and "activates" the card, the "active" field is then set to Y. Is this a practical/clean/logical way to set up a scenario such as this? I have been using MySQL for a couple years now, but it was all self-taught, so I have a lot of the fine details to still learn.
  8. Is there anyway to condense these three queries into one query? Or am I limited to running each query individually? // to get the total number of cards in the database $countTotalCardsStr = "SELECT COUNT(card_number) FROM user_cards"; // to get a count of all the cards that have been activated $countActiveCardsStr = "SELECT COUNT(card_number) FROM user_cards WHERE active = 'Y'"; // to get a count of all the cards that have not been activated yet $countInactiveCardsStr = "SELECT COUNT(card_number) FROM user_cards WHERE active = 'N'"; Thanks in advance!
  9. This is the first time I have had to work with numbers that extend past 16 digits long. Here is the background behind this script: a user/admin manually types in the START NUMBER of a range of card numbers. Then the user/admin types in the END NUMBER of that set of card numbers. Then the form is submitted. After I run all of my checks to make sure the form variables are posted, they are numbers, 19 digits long, etc, I need to loop through the start to the end of the range entered. This is what I came up with (assuming startRange is 1111111111111111111 and endRange is 111111111111111113): // start the beginning of the sql statement that will be used to insert the card number range into the DB // this is so we can insert multiple rows with just one query $tempSQL = "INSERT INTO user_cards (card_number, active, sponsor_id, created_date, last_updated_date) VALUES"; // get the difference between the END RANGE and the START RANGE so we can use this as the conditional statement in the foor loop $bcDiff = bcsub($endRange, $startRange, 0); // start for loop // $i set to zero because we need to start off adding 0 to the very first startRange var for($i=0; $i <= $bcDiff; $i++){ $tempCardNumber = bcadd($startRange, $i, 0); // append this onto the end of the $tempSQL string so we can insert multiple rows with just one query $tempSQL .= " ('$tempCardNumber', 'N', '$tempSponsor', NOW(), NOW()),"; } // strip the last comma from the end of the $tempSQL string $tempSQL = substr($tempSQL, 0, -1); Is this clean, practical and safe programming? Any constructive criticism?
  10. Ok, now I know how to compare 19 digit numbers to one another, but here is the new problem. How I do increment 19 digit numbers? For example, I have: $startRange = '1111111111111111111' $endRange = '1111111111111111119' I have a for loop that starts off at the $startRange, and ends when it equals the $endRage. But every time I increment the $startRange, I end up with 3.3333333333333E+18 instead of 1111111111111111112, 1111111111111111113, etc. Does anyone have aquick fix, as well as a good tutorial or the actual PHP page that describes working with numbers so I can get a better understanding of what is going on. Thanks in advance!
  11. bccomp worked PERFECTLY! Thanks Patrick!
  12. I tried something very similar to this in the beginning, but because integers are only evaluated to 16 digits (from my understanding) and I need 19 digits, it would not work.
  13. I need to be able to compare some 19 digit numbers (in regards to < or >). I obviously keep on running into the problem that when ever I try to use the examples: $startRange = 1111111111111111119 $endRange = 1111111111111111111 What do I need to do to be able to compare these larger numbers? What I want to check more specifically is that the $startRange is not larger then $endRange. Thanks in advance!
  14. This is the first time I have researched and used the $$ syntax before. I guess I miss understood it's exact use. Thanks for the advice! i didn't even think using a combination of the two possibilities.
  15. I have a signup form that has 19 small textboxes that will be populated with one number PER textbox from the user. The textboxes on the signup form are respectively called: card1, card2, card3....card18, card19. For my form validation, I know I could do the longhand version of: [pre] if(isset($_POST['card1'] && $_POST['card1'] != "" && is_numeric($_POST['card1']) && strlen($_POST['card1']) == 1) { //proceed } else{ // setup error message(s) } [/pre] ...and reproduce this for the other 18 textboxes relatively easily, but I would rather learn the more efficient and correct way to do. Here is what I came up with: [pre] for ($i = 1; $i<=19;$i++){ $var = 'card'.$i; $temp = $_POST[$var]; if($$var == "" || !is_numeric($$var) || strlen($$var) != 1){ // error message of some sort } } [/pre] Any criticism/suggestions? I don't cry for that long and I don't hold grudges, so please come with it
×
×
  • 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.