Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=356124.0
  2. As seanlim stated this is not a PHP or a JavaScript problem. This requires CSS. This site is called PHP Freaks, but there are more than just the PHP Forum. We also have forums for JavaScript, CSS, HTML, MySQL, etc., etc. Please post int he right form. Moving this to the CSS forum.
  3. Well, you need to decide if you will EVER need to store non whole-dollar values in the database. If so, then you shoudl definitely use a float/decimal type in the database. But, even then you should probably force the format when it is displayed to be what you want. If you will ONLY ever have whole-dollar amounts you can stick with an int. Some options for formatting the value: If you are going to stay with ints, you could simply append '.00' to the value as you display it. It would work, but seems hokey to me. Use number_format(). This would work with any type of value that can be interpreted as a number. This is probably the easiest implementation. Use money_format(). This is very useful if you ever want to account for localization.
  4. Next time, put the output in [ code ] tags so it isn't modified into smilies . Anyway, something doesn't seem right. The value from the DB is "22782.20" and after formatting with number_format() it is unchanged. I just rant the same test with hard-coding the same value to test with - I even forced the value to be a string: $row['P28_maxdoz'] = (string) "22782.20"; $P28_maxdoz = number_format($row['P28_maxdoz'], 2, '.', ','); echo "Value from DB: "; var_dump($row['P28_maxdoz']); echo "<br>Value after format: "; var_dump($P28_maxdoz); My output: Value from DB: string( "22782.20" Value after format: string(9) "22,782.20" Even if your server had a non-US localization set, the 3rd and 4th parameters of number_format() should have overridden the defaults.
  5. Although, if it is possible that the user may type in the index.php and you always want the parent folder, then this would work as well $root_folder = basename($_SERVER['REQUEST_URI']); if(substr($root_folder, -4) == '.php') { $root_folder = basename(dirname($_SERVER['REQUEST_URI'])); }
  6. basename($_SERVER['REQUEST_URI']);
  7. Hmm, are you sure the value from the database is a number to begin with? Try the following and post what you get: $P28_maxdoz = number_format($row['P28_maxdoz'], 2, '.', ','); echo "Value from DB: " . var_dump($row['P28_maxdoz']); echo "<br>Value after format: " . var_dump($P28_maxdoz);
  8. Not quite sure what you are after when you say Are you saying you want to terminate the session if the user leaves the browser window open? That's the only thing that makes sense since there could not be any ajax calls if the browser was closed. So, to rephrase, the user is in the application and then decides to leave the browser open and you want to time-out the page or something similar. There are some different solutions I can think of, but I think the one that makes the most sense is as follows: Simply create a a"last activity" process that updated a timestamp for the user record whenever the USER performs an action that you determine should update that value (i.e. not an automated AJAX call). Then, when the automated AJAX call is performed you can check the user's last activity timestamp. If less than the timeout period you specify then go ahead and process normally. If greater than the timeout period do not perform the action and send a response back to the client so the JavaScript can stop the automated process and provide a message to the user.
  9. The error is pretty obvious. It appears you are using the hashed value (it is not encryption) as the field name for the password. Also, in the future, it would be appreciated to just post the relevant code for your problem, not the whole script. Here is your current query: $sql="INSERT INTO `registernow_2012`.`users` ( `id` , `name` , `username` , `$enc_password` , `confirm_password` ) VALUES ( NULL , '$_POST[name]', '$_POST[username]', '[$enc_password]', '$_POST[confirm_password]' )"; You are using "$enc_password" as a field name. You also have a field for "confirm_password". That doesn't make sense since that is typically used as the 2nd entry field for the password and is only used for validation purposes and is not stored. As you can see you have put the VALUE of the hashed value in the field list and not in the values list. You need to use an appropriate field to store the value - I will assume "password". So, you need to fix. Plus, you don't need to include the "id" in the field list if you are just going to pass a null value. $sql = "INSERT INTO `registernow_2012`.`users` (`name`, `username`, `confirm_password`) VALUES ('{$_POST['name']}', '{$_POST['username']}', '{$enc_password}')"; Lastly, the above script is wide-open to SQL Injection. You need to validate/sanitize the values appropriately based upon the type of data you expect and the storage type. And, you should look into using a hash that uses a salt - plenty of posts on this forum and elsewhere on how to do that.
  10. Your queries are not what you think they are. When having problems with queries that are dynamically generated it helps if you echo them to the page and then the problems will be easier to spot. Also, it makes it MUCH easier to see these types of errors if you indent the lines of code based upon the logical structure. Here is what you currently have: $query_Recordset2 = sprintf("SELECT ast_formID, ast_model, ast_ownName, ast_ownDept, stf_id FROM asset WHERE ast_ownName LIKE '$colname_Recordset2%' ORDER BY ast_ownName ASC", GetSQLValueString($colname_Recordset2 . "%", "text") ); You are using sprintf() with a formatted string (the query) and one argument. But, the arguments are used to replace placeholders in the formatted string. Your formatted string has no placeholders. Instead you are setting the latter to match as "$colname_Recordset"!. I don't know what value is the first letter of the user entered value of what the function GetSQLValueString() is supposed to do. The logic makes no sense to me, but I think your query builder should look like this mysql_select_db($database_COS, $COS); $query_rs2 = sprintf("SELECT ast_formID, ast_model, ast_ownName, ast_ownDept, stf_id FROM asset WHERE ast_ownName LIKE '%s' ORDER BY ast_ownName ASC", GetSQLValueString($FIRST_LETTER_OF_USER_ENTERED_VALUE . "%", "text") ); $query_rs2_limit = sprintf("%s LIMIT %d, %d", $startRow_Recordset2, $maxRows_Recordset2 ); $Recordset2 = mysql_query($query_rs2_limit, $COS) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); if (isset($_GET['totalRows_Recordset2'])) { $totalRows_Recordset2 = $_GET['totalRows_Recordset2']; } else { $all_Recordset2 = mysql_query($query_rs2); $totalRows_Recordset2 = mysql_num_rows($all_Recordset2); } $totalPages_Recordset2 = ceil($totalRows_Recordset2/$maxRows_Recordset2)-1; }
  11. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356016.0
  12. No problem, that's your decision. Good luck.
  13. how about changing it to a MySQL date/time type instead of an int? You won't be able to use any of the MySQL date functions by storing a PHP timestamp.
  14. You should be storing dates as date types into your database. Don't' make up a format or store them as PHP timestamp values. It will make yuur life more difficult int he long run. What type of field are you using now?
  15. Psycho

    GET and IF

    Yes, I know what was meant and I could have written that very easily. if(isset($_GET['code'])) { //Activation code } elseif(isset($_POST['submit']) { //Process post data } else { //Show form } But, if you are using the same script for the form and processing it is typical to have the processing logic drop-back to the form when there is a validation error. The logic I first provided will work exactly the same as the above but with the added benefit of being able to revert back to the form when there is an error in the POST data. Regarding the isset() on the 'SUBMIT' value, I wouldn't even check a required field. Instead, I would check the REQUEST_METHOD. But, that is another subject that I felt would confuse the issue at hand.
  16. Psycho

    GET and IF

    Why do you want to make all these into one page? I always find it best to have my logic broken down into small files - then include the ones as needed. Anyway, there are several ways to put this logic together. Here is one example if(isset($_GET['code'])) { //Perform activation code here } else { if(isset($_POST['submit'])) { //Perform form validation/processing processes //If everything passes redirect to a confirmation page //If validation fails then code will drop-them back down to the form } //Add code here to show form }
  17. I agree, it is irrelevant with respect to the data needed, but the previous pattern would not match the lines because the pattern was looking for a line that starts with "GPRMC". Therefore, when run against the sample data provided, there were no matches. The test data showed for that first regex you provided took out the dollar sign, so it worked. I did not read every line in detail in his sample input. But, I did specifically state right before that code And then I also gave a solution that would work across multiple lines, if needed.
  18. Have you tried just using htmlspecialchars() or htmlentities()?
  19. What he said. Using JavaScript is a really poor solution. There are sometimes hurdles when dealing with checkboxes - such as when you have a series of checkboxes to EDIT existing values. But, there are tried and true methods of handling those.
  20. I'm not sure I agree with that assessment, because you would only see the BR tags if he posted the source. Well, his input data explicitly showed the BR (and other) tags and his required output explicitly excluded all of the tags. So, I took that to mean he wanted the HTML markup removed and logical line breaks replacing the HTML linebreak tags.Of course he did state "I want it to look like" and that could be construed to only mean the "displayed" output. But, in that case the original content was fine to begin with. In any case, the fact that we interpreted the requirement differently means the request was not clear.
  21. That solution fails with the exact content the OP posted (i.e. the leading dollar sign.) @cr-ispinternet: Is the line you want always the first line in the output? If so, a better solution might be to get the first line. $GPRMC_line = array_shift(explode("\n", $gps_output)); Although you may have to play with the delimiter, could be "\n", "\r" or "\n\r" But, if you need to use regular expression, this would work too preg_match("#$GPRMC.*#", $input, $match); $GPRMC_line = $match[0];
  22. Based upon the OPs description and example input/output data this should work function removeHTML($inputStr) { $outputStr = preg_replace('#<br>|<br/>#i', "\n", $inputStr); $outputStr = strip_tags($outputStr); return $outputStr; }
  23. His output doesn't show any HTML, not even BR tags. It looks like BR tags should be replaced with a line break. So, I would use a preg_replace() to change any BR tags to line breaks then use strip_tags() to remove any and all remaining tags. Note: I'd use preg_replace() instead of str_replace() to cover all the variations of BR tags.
  24. Well, you might be checking ONE variable, but that doesn't mean there isn't another problem in the query. Heck, maybe the value you are checking isn't correct for the field you are trying to save it to. But, there is a pretty easy way to find out what the problem is - check the error. First off, create your query as a variable, so if there is a problem you can echo it to the page. BUt, at least one of your problems is that you are not enclosing the values in quotes. If those values/fields are anything but numeric fields that will certainly create an error. $query = "INSERT INTO airline_survey (staff, luggage, seating, clean, noise) VALUES ('$staff', '$luggage', '$seating', '$clean', '$noise')"; $result = mysql_query($query); if(!$result) { echo "Query failed. Query:<br>$query<br>Error:<br>" . mysql_error(); } else { echo "Query succeeded"; }
  25. OK, then there is probably no need to jump through the hoops you are doing now to get the results you want. You can just as easily generate this output when you extract the results from the query. Creating an array is probably pointless. Can you show the code you have for running and processing the query?
×
×
  • 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.