Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Yeah, I noticed that. You will want to change the slanted quote marks to strait quote marks: '
  2. I'm confused as well. In the script above you are generating a random number and 1) creating a new record in the database and setting one of the fields to that value and then 2) setting a session variable to the same value. You are saying the two values do not match. Exactly "WHERE" do they not match? You are obviously not comparing the two variables in the above script, so I must assume you are seeing the problem on another page. I will further assume you are storing the code as a session variable so you can grab the user's data from the database on subsequent page loads. So, are your queries returning no records on subsequent pages (i.e. no record is returned)? I don't see you starting the session in the above code. Don't know if that is the problem or if you jest left that off for brevity. Basically, what you are asking makes no sense within the context of the code you have provided.
  3. Exactly the same way you create it. You take the password the user enters on login and apply the EXACT same hashing/salting algorithym and compare it to the value in the database. I would highly suggest creating a single function to create your hashed value to use when storing new password and for comparing passwords at login. That will ensure you are doing exactly the same thing in both instances.
  4. I'll take a look at the code you posted, but here is another resource. http://www.dynamicguru.com/php/currency-conversion-using-php-and-google-calculator-api/
  5. You need to determine the draw date/time in the code; then determining if the user is submitting their numbers too close to the draw is very simple. However, since I assume there are going to be multiple draws, you need to decide how you will determine the draw that the person is submitting numbers for. Are you only going to allow them to submit numbers for the next draw or can they submit numbers for any future draw? Anyway, once you have decided on that logic here is how you can test if the submission is x minutes before the draw. You can either get the draw date/time into logical values for hour, minute, second (or just use zero), month, day & year; then use mktime(). Or you can get the date/time of the draw in a string format and use strtotime(); $cutoffTime = 60; //Cutoff in minutes $drawTime = mktime($drawHour, $drawMinute, 0, $drawMonth, $drawDay, $drawYear); //Test if the timestamp (in seconds) for the drawtime minus the //timestamp for NOW (i.e. the number of seconds from now until //the draw) is less than the cutoff time in seconds. if($drawTime-time() < $cutoffTime*60) { //Submission is after the cutoff time // - add error handling } else { //Submission on or before the cutoff time // - allow the submission }
  6. If this really is for "products" then you should be storing this data in a database. You would have one table for the products, a second table to list the 'possible' product features and a third table to associate the appropriate features to the appropriate products. If this is merely for hypothetical purposes or for elements that will not hcnage then you could use a multidimensional array 'ProductA' => array( ), 'ProductA' => array('AAAAAA', 'BBBBBBB', 'CCC', 'DDDDD', 'EEEEEEE', 'FFFFFF', 'GGGGGGGG'), 'ProductB' => array('YYYYY', 'BBBBBBB', 'CCC', 'UUUUU', 'ZZZZZZZZZ', 'MMMMMM'),
  7. Okay. Is there a question in there somewhere? You apparently already have the code to conver to binary. So, now you just need to save it to a file. You need to decide "how" it will be saved. You can save it delimited in some manner (e.g. tab or comma delimited) in which case you don't need to worry about the leading zeros. Or, if you want to store it as one really long string of zero's and one's then you will want to pad the binary valules so they are a consistent length.
  8. Because numbers do not begin with 0. If an items costs fifty dollars you never see it represented as $050 do you? Just because many binary numbers are representative of values that can range from 0 to 256 (i.e. 8 bits) does not mean that all binary numbers are limited to that space. They can be less than or greater than 8 bits. If you need the value presented to the user as representiing 8 bits, then simply use string_pad() or sprintf().
  9. Exactly. You can reduce the code down to a single line as follows: $array1 = array( 1, 6 ); $array2 = array( 5, 6 ); echo 'Highest unique array value in $array2: ' . max(array_diff($array2, $array1));
  10. The formatting IS being retained when you save to the DB - line breaks and all. The problem is that the browser does not process linebreaks when rendering code - not without specific tags such as <PRE>. But, you don't want to use <PRE> for this anyway. Just save the input to the database as normal (don't add <BR> tags). Then on the page where you display the output use nl2br() to output the text. That function will automatically convert nel lines to <BR /> tags.
  11. So, I am guessing that "other rows where the email field has NO value " means that the value is a logical NULL instead of an empty string. Because using "<> $session_email" would return those records that have an empty string as the value. That would also occur if you were joining two tables and there was no matching record in the second table - in that case you just need to use the correct JOIN. SELECT * FROM table WHERE email_address <> '$session_email' OR email_address IS NULL If the problem has to do with JOINING two tables where there is no matching record in the second table, use a LEFT JOIN.
  12. Yeah, I thought about all of that when I posted the code. I figured that something like "100.", "100.1", and ".1" were all valid currency values that could be logically interpreted by the code correctly. However, the real "issue" with the code I posted is that a single decimal point would also pass the validation. I figured the processing code could be written to interpret that value as zero.
  13. Well, personally I would only validate on submission of the form instead of trying to limit input. But, you can modify that function pretty easily to also accept decimal points. But, that won't prevent users from entering invalid number (e.g. 123.4567, 123.45.67, etc). So, I would take a two-pronged approach: 1) Only allow numbers and periods to be entered and then on submission validate that the value is a valid number with no more than two decimal places: <html> <head> <script type="text/javascript"> function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode; return (charCode<=31 || charCode==46 || (charCode>=48 && charCode<=57)); } function validCurrency(amt) { return amt.match(/^\d*(.\d{0,2})?$/); } function validateForm(formObj) { if(!validCurrency(document.getElementById('amount').value)) { alert('You must enter a valid dollar amount.'); document.getElementById('amount').select(); document.getElementById('amount').focus(); return false; } return true; } </script> </head> <body> <form name="test" action="" onsubmit="return validateForm(this);"> Amount: <input type="text" id="amount" onkeypress="return isNumberKey(this);"> <br /> <button type="submit">submit</button> </form> </body> </html>
  14. You must not have read my signature which states I don't always test my code. I expect users to at least be able to identify and fix simple syntax errors. I suspect the error you are receiving is due to the fact that I left a comma after the last array element. But, I'm not guaranteeing there are not others.
  15. You need to elaborate on what you mean by "when the page is reloaded". If you mean reload as in the user clicks the refresh button, that becomes an elaborate solution as it would require AJAX code to fire wheneveer a change is made to the select list. I think the people above assumed - as did I - that you meant if the user submits the form you wanted to redisplay the field with the submitted value pre-selected. If so, that data is sent within the $_POST variable since that is the method you specified in the FORM tag. This has nothing to do with storing the values in the database (although you are free to do that if you wish). Your code would suggest that changing the select option is submitting the form based on the onchange trigger. As for preselecting the value, here is a more elegant solution than the ones posted previously: <?php $options = array( -1 => 'Select an Industry', 0 => '------------------', 1 => 'Digital Media', 2 => 'Software', 3 => 'Telecommunication', ); $selected = (isset($_POST['industry'])) ? $_POST['industry'] : fasle; $options = ''; foreach($options as $value => $label) { $options .= "<option value=\"{$value}\">{$lable}</option>\n"; } ?> <select name="industry" id="industry" onchange="if(this.options[this.selectedIndex].value>0){ this.form.submit(); }"> <?php echo $options; ?> </select>
  16. You are also making this more difficult than it needs to be. MySQL allows you to add an attribute called "ON UPDATE CURRENT_TIMESTAMP". Just set that attribute for the "last access field". Then when a user logs in update the "ip_address", "browser" and "hostname" fields and the "last access" timestamp will be updated automatically.
  17. You can just use number_format() by itself since it can round as well as format: number_format($input, 2, ',', '.');
  18. So you are saying that out of all the hundreds of thousands of applications that don't need to use eval() your app is a special case? Not buying it. There are many reasons that you should never use eval() - and I'm not going to go into them here. There are plenty of resources available to explain why it is a very bad decision.
  19. OK, I will suggest a combination of what MrAdam suggested AND a queue system. Without doing some testing I can't be sure, but I suspect the problem is not with the submission of the data, but in the processing of the data. At the very least you should add some debugging code to the processing page to determine how long the page is taking to process. You could even add code to capture teh execution time at specific points in the processing to determine where the slow down is occuring. At the very least you will determine if the problem is with the processing of the data and where, specifically, it is occuring. Then, assuming the problem is with the processing you can do a couple of things. One, you might be able to identify some easy fixes to improve the processing. E.g. are there any database queries being run in a loop? That will be a huge resource hog. If you can't determine any fixes, just post the relevant code here and I'm sure we can help. Second, if you can't determine a fix for any slow processing then you can implement a queue system for the processing of the data. I would allow people to go ahead and submit their data as they please. But, instead of immmediately processing the data, just add the raw data to a temporary table. Then have a scheduled script that actually processes the data as needed.
  20. Yes it is possible, but any programmer decent programmer would tell you that is a very poor method of doing what you are trying to achieve. You should never need to execute a string as PHP code. Why not evaluate "number_format(1000)" before you store the data then just store the complete string? Then you simply need to grab the value from the database and echo it to the page. There is a function for this, but if you think you need to use it you need to do some research to verify that there isn't a more appropriate way of accomplishing the same task. Once you are convinced that you still need to execute a string as code, you need to go back and research some more because you obviously missed something. Although, what you are asking for is NOT the solution you should be following, the answer to your question is to use eval().
  21. For phone number validation I just strip out all non-numeric characters and then test the length. But, depending upon "where" your users may be from this may not be a trivial task, e.g. international users. But, for the sake of argument, let's say you expect all users to be from the US. I would first include text on the form to tell the user they must enter their full phone number, including the area code. Something such as: Phone: ____________ (xxx) xxx-xxxx Then, when processing the input, call a function such as this: function validPhone($phone) { $phone = preg_replace("/[^\d]/", '', $phone); return (strlen($phone)==10) ? $phone : false; } The function will return just the numeric digits (if only 10) or will return false, so you can perform whatever error handling is needed.
  22. Echoin'g Pickachu's comment, it would be better to know what exactly you are doing, but this might work as a "quick fix" to reindex the values starting at 0. $_SESSION['items'] = array_values($_SESSION['items']);
  23. Are you even sure that the IF statement is resulting to TRUE? Your code is assuming values are present and you shouldn't use a variable as the condition of a comparison to check if the value is set or has a value. What does the following output? $itemlisted = (isset($_POST['itemlisted'])) ? trim($_POST['itemlisted']) : ''; if (!empty($itemlisted)) { echo "Posted value: {$itemlisted}<br />"; echo "SESSION Before unset: <br />"; print_r($_SESSION); unset($_SESSION['items'][$itemlisted]); echo "SESSION After unset: <br />"; print_r($_SESSION); }
  24. Of course, you could have found this information yourself by simply reading the manual regarding arrays. http://php.net/manual/en/language.types.array.php Not only will it take a few milliseconds longer to process, the code could stop working entirely in future versions of PHP if they decide to fix that "bug".
  25. There's a lot of ivalid HTML markup in that code. For example, once you open a table, any "non table" markup should only be inside TD or TH tags until the table is closed. Anyway, add this trigger to your select tag: onchange="displayText(this);" Then create a DIV for the text to be displayed in and give it an ID parameter, such as "description" Then add this to the head of the document: <script type="text/javascript"> function displayText(selObj) { var selVal = selObj.options[selObj.selectedIndex].value; var outputObj = document.getElementById('description'); switch(selVal) { case 'Apple': outputObj.innerHTML = 'A green fruit'; break; case 'Lime': outputObj.innerHTML = 'Another green fruit'; break; case 'Banana': outputObj.innerHTML = 'A yellow fruit' break; default: outputObj.innerHTML = '' } } </script>
×
×
  • 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.