Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. Sounds like you need to do one of two things 1) Merge the names into the posts array, putting the names into their associated posts. You can do this with a couple foreach loops probably. 2) Change your JS code to work with two separate arrays instead of of a single array. Then just encode them both, a la json_encode(array($names, $posts));
  2. Sounds like now it's time to start debugging your JS code to see what it is doing. If it comes back from PHP ok then something in your JS must be causing it to skip rows. If your using a pre-packaged script to do things read the docs and make sure it is setup properly. If it's your own code start tossing in some console.log statements to find out what it is doing.
  3. The code form the PHP side of things is the same for this query as it would be for any other SELECT query your running anywhere on your site. You just have what some call a 'calculated column' which is essentially an additional column derived from the value of other columns. To your PHP script it appears the same as any other column in your tables. You really need to develop an understanding of how the functions work to accomplish a task, not just copy-n-paste them over and over. Experiment with them, try different things. 90% of learning is trying and seeing what happens. When you understand what the functions actually do things will make more sense and it'll be easier for you to adapt to new situations. Your create_password script has no bearing on any of this, unless your trying to also use that script as your reset password script. If you are, just separate the two into different scripts. You don't tweak the prepared statement. You tweak the query, and you do so just like I showed by doing the date math in the query itself and getting the result as a new separate column. After you run your statement for the SELECT query you use the mysqli_stmt_bind_result to assign a variable to each column your selecting. All you have to do is assign the results of that date math to a variable for use in PHP. This may not be entirely correct as it has been a long time since I used mysqli, an of course you'll have to update it to your table layout and needs, but essentially you would have something like this: $sql = ' SELECT TIMESTAMP_DIFF(HOUR, NOW(), temp_reset_on) as tmpPassAge FROM members WHERE member_email=? '; $stmt = mysql_prepare($sql); mysql_stmt_bind_param($stmt, 's', $_GET['memberEmail']); if (mysqli_stmt_execute($stmt)){ mysqli_stmt_store_result($stmt); mysqli_stmt_bind_result($stmt, $tmpPassAge); if (mysqli_stmt_fetch($stmt)){ //record found, test for expired pass if ($tmpPassAge >= 4){ //pass expired } else { //continue } } } If you want to learn anything well you have to be willing to take a chance that you might mess something up. Of course, you want to try and ensure messing something up has as little impact as possible but sometimes in the spirit of learning you just gotta do stuff. You should get a test environment setup which is completely separate from your live website that you can do all this testing/possibly breaking stuff on. Then if you do mess something up, you just restore your test environment and no harm done to your live data. Once you have it all working like you want to push the change to your host and "go live". It's pretty easy to setup a local copy of apache/mysql/php these days using setup programs like xampp. Your host probably has some method of creating a backup of your mysql database which you can then import into your local setup so you can experiment without causing any harm to your live site. side note: took me so long to type this ya'll posted a bunch of stuff already. I must learn to type faster.
  4. Set a variable that you can use in your template to control which piece to display. eg: <?php if ($UserLoggedIn): ?> <h1>Welcome <?php echo $Username; ?></h1> <?php else: ?> <form> <!-- show login form </form> <?php endif; ?>
  5. Use dev tools like firebug, chrome dev tools, or fiddler2 to view the ajax transaction that takes place and inspect the data being returned by your script to see if it is missing the rows or if the data is just malformed somehow.
  6. Mysql has it's own format that it stores dates in, which allows it to store a large range of dates as well as do calculations on these dates. NOW() is a mysql function that just returns the current date in the mysql format. UNIX_TIMESTAMP() is another mysql function which will convert dates in it's format to a unix timestamp format. Once you have it in unix timestamp format (which is just # of seconds since 1/1/1970 @ midnight) finding out the age is just a matter of subtracting that timestamp from the current timestamp (given by PHP's time() function). This will give you the age in # of seconds. 4 hours = 60*60*4 = 14400 seconds. All that said, it's often better to do any date calculations or formatting in your SQL query directly instead of having to translate them back-n-fourth between mysql and php. Eg: SELECT *, TIMESTAMP_DIFF(HOUR, NOW(), temp_reset_on) as tmpPassAge FROM members ... Then in your code you can just do if ($row['tmpPassAge'] >= 4)
  7. There may be instances where you don't want/need to pass a name=value set in the query string, but instead just a value. In those cases you would need to use $_SERVER['QUERY_STRING'] to get it. For example: /error.php?404 or /error.php?500 switch ($_SERVER['QUERY_STRING']){ case '404': //404 error message case '500': //500 error message }
  8. You can get a list of all the key names using array_keys, convert them all to lowercase using strtolower+array_map and then check if your value exists in that array. <?php function array_key_exists_case($arr, $keyName){ $allKeys=array_keys($arr); $allKeysLower=array_map('strtolower', $allKeys); $idx = array_search(strtolower($keyName), $allKeysLower); if ($idx===false){ return false; } else { return $allKeys[$idx]; } } That function will check if the key exists in a case insensitive manner. It will return false if it does not exist. If it does exist, it returns the key in the case it exists as so you can use that to access the value.
  9. Because I am trying to get my "reset_password.php" working and am stuck deep in my code... You can always create a new fresh file just to test a particular thing, especially something as simple as this. <?php $value='198248'; $regex='/^\d+$/'; if (!preg_match($regex, $value)){ echo 'Hey, it works!'; } else { echo 'Oops'; } That said, ! means not so if you have a function that tests a condition, and you want to know if that condition is not true you can just prefix it with ! to reverse the returned boolean value. !true = false, !false = true.
  10. Everything after the ? in a URL is known as the query-string It's generally a set of name=value pairs separated by &. When you see them in page urls they are generally parameters that the script generating the page uses in the generation process (eg, db id's, search terms, etc). When you see something like in your given example, it is likely just there to ensure the most recent copy of that css file is used instead of an older cached copy.
  11. You login script would only look at the actual password hash field. Scootsah's method (and what I do aswell) involves just creating some temporary code which is used only for the reset. Process goes something like this: [*]User requests a password reset by entering their email [*]Find the user by email and generate a random value. uniqid or a quick md5 of say the email+current time is good enough [*]Save that value as well as the current datetime into that user's db record in new fields, ex: ResetCode, ResetRequestedOn [*]Email the user a link such as http://www.example.com/resetpass.php?code=<the generated code here> [*]When the user visits that link, take the code and attempt to find a record with that code (SELECT ... WHERE ResetCode=:theCodeFromUrl) [*]If found, and the the difference between ResetRequestedOn and now is less than, say 24 hours, show them a form where they enter their new password [*]Save their new password to the database, optionally with a new salt value, and NULL-out the ResetCode and ResetRequestedOn fields
  12. After that, does the original password still work? What happens if I go there and submit a reset request on behalf of some user then they just delete the email rather than follow the process.
  13. That is not a valid entity. &#117; is, note the ; on the end. Browsers are more forgiving of errors.
  14. Once the Page has been generated and handed off to the browser for rendering, PHP is done. At that point anything you want to do either requires the use of javascript, or a page reload via clicking a link or submitting a form. So basically, no, you want javascript.
  15. &#000117; is an entity just like the hex ones I showed above. Instead of using a hex encoded value it is an octal encoded value though. html_entity_decode should be able to decode them into their char values. You just need to make sure they are in the correct format, meaning they need to have a ; after the number sequence to end the entity.
  16. Your javascript code doesn't matter as it is not the one that needs to access the file. All you need in your JS code is some value that you can pass to the PHP script which represents which file it needs to use. The base filename without any path info should be sufficient.
  17. Your PHP script can access the files outside the document root just fine. You just need to make sure the path to them is correct. It may be easiest to have your page/js have only the font's filename and keep the path static in the PHP file. So you end up with a URL like: sample.php?font=CORBELB.TTF And in your PHP you would have something like: <?php define('FONT_PATH', '/the/absolute/path/to/the/fonts/'); $fontFile = FONT_PATH.$_GET['font'];
  18. I've never used FastCGI so I'm not well versed in it. This is just my understanding of the process, not sure on it's accuracy. FastCGI does re-use the same process for requests yes, but it does not use the same process for all requests. It will spawn several processes which all process requests as they come in. FastCGI will distribute the requests among all these processes as they come in so there shouldn't be any, or much anyway, waiting around for requests to complete.
  19. It means you count every ( you have and every ) you have. If the number doesn't match, then you have a problem. When you start dealing with lines like that, it often is better to fill in a few temporary variables and use those. $subTotal = $_SESSION['order']['contentvalue'] + $_SESSION['order']['deliverycost'] * 1.01; $total = $subTotal + $_SESSION['order']['paymentsurcharge']; $total = floor($total*100)/100; Much easier to read and follow; number_format should take care of that for you.
  20. If you use var_dump($info); it will show you the entire content of $info and which keys are defined. Then when you see your keys are missing just trace the execution backwards and figure out why they are missing. My guess? You have a mix of some forums which both do and don't contain any sub forums. For forums that have no subforums, you never define those keys.
  21. More or less. Each case marks a jump point. When PHP matches the value given to the switch to a given case value, it jumps to that location in the code and resumes execution from that point. It will keep executing from there until it encounters something that causes it to break out (end of switch, break statement, return-statemt). In the code above, both the 'list' case and the default case correspond to the same jump point so in either case it goes to the same place in the code. I could drop the "case 'list':" line all together and just have the default, but I prefer having the case line there to clearly mark it.
  22. Give you default a case label as well and use that. For example I do this on a lot of my pages: $action = isset($_GET['action'])?$_GET['action']:'list'; switch ($action){ case 'add': //... break; case 'edit': //... break; case 'delete': //... break; case 'list': default: //... break; } That makes it so that if the action is list, or any other un-recongized value it runs the default case.
  23. The documentation for the sqlsrv_* functions is on microsoft's site at http://msdn.microsoft.com/en-us/library/cc296152.aspx. The params parameter should be an array of values to put in the placeholders. You only have one placeholder but your given it two values for params. It's subbing in the value 1 for your placeholder which is an int. As a result it is trying to cast the column value to an int to do the comparison but it cant so you get the error. You want to only pass one value which is your $table variable.
  24. Again, works fine for me. Same variables problem? kicken@linode:~$ php -r 'echo number_format(150 + 20.95 * 1.01 + .5, 2);' 171.66
  25. Her photos are actually not bad quality wise (from what see) so whatever camera they used seems to be decent. The presentation leaves a lot to be desired though. The dishes need to be prepared well so they look nice. Better lighting and angles would go a long way as well. I'd ask why she doesn't want to use the stock images. Could be that she wants a more personal touch on the site by showing actual dishes they make there, maybe featuring some special dishes that would be harder to find a good stock for.
×
×
  • 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.