Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. Works just fine for me. kicken@linode:~$ php -r 'echo number_format(150 + 20.95 + .5, 2);' 171.45
  2. Variables are not translated when used in single-quoted strings. So your trying to copy your image to a directory literally named '$memberID' rather than one with that ID value. Use double quotes or concatenate.
  3. Because 99 does not equal 0 (which is what the strings get converted to). Therefore none of you cases match so it goes to the default case.
  4. Those are HTML entity sequences. To convert them to their actual characters you just take the hex code, convert it to decimal and then get that chr() value. It can be done with a simple preg_replace: $str="SIA"; $re = '/&#x([0-9A-F]{2});/ie'; var_dump(preg_replace($re, 'chr(hexdec("$1"));', $str)); Once you've converted it back to a normal string using a replace such as that, you should be able to use the encoding functions to detect or convert it as necessary.
  5. A quick array_intersect and count should work. <?php $a1 = array(2,4,6,; $a2 = array(1,2,3,4,5,6,7,8,9,10); function issubset($arr1, $arr2){ return count($a1)==count(array_intersect($a1, $a2)); } var_dump(issubset($a1, $a2));
  6. Put a NULL in that field during the insert, then after you get the ID and move the file run an UPDATE which changes it to the actual value. Because he has to run the query before he can get the insert id that is used to generate the file name.
  7. Every time you put a new line between your tags your making a text node. There is nothing wrong with having several text nodes within a particular element. Even having two right next to each other is ok, just typically they get combined together into a single one. Take for example the following HTML which would be something fairly typical. <h2>Hello <a href="profile">kicken</a>, welcome to <a href="phpfreaks">phpfreaks</a>.</h2> That h2 element has three different text nodes. Most xml based formats tend to avoid mixing text and elements such as the above, as it's easier to work with when elements only contain elements, or only contain text.
  8. Precisely. When comparing a string value and a numeric value, PHP opts to convert the string to a number. Since all your string values are invalid numbers they all equal 0, and php just goes to the first one in the list. If for example, you had done something like this (just an example to throw in a number): switch (0){ // Insert Succeeded. case '3D_ACCOUNT_MEMBER_ACCT_CREATED': echo '<h1>Member Account Created</h1>'; echo '<p>Congratulations!</p> <p>Your account has been created, and a confirmation e-mail sent to: "' . $email . '"</p> <p>Please click on the link in that e-mail to activate your account.</p>'; break; // Insert Failed. case 'ACCOUNT_MEMBER_ACCT_FAILED': echo '<h1>Account Creation Failed</h1>'; echo '<p>You could not be registered due to a system error.</p>'; echo '<p>Please contact the System Administrator.</p>'; break; } PHP would start at the second case because the first one would convert to the number 3, which does not equal zero. You can manually cast to a string to ensure PHP converts your code rather than the strings. eg: switch ((string)$resultsCode){
  9. It allows whoever knows how to use it the ability to both upload arbitrary files as well as execute arbitrary code (either directly or via the new files). You'll want to do a full check for any other mysterious files on your system.
  10. Sure. Wordpress for example is procedural. If the code is well organized and design a procedural approach can be just as effective as an OOP approach.
  11. If someone clicks a link or just enters the URL in the browser it will be a GET request that is sent to your server. If the request is not a POST, it obviously has to be something else. Given the information that was provided in various replies as well as the linked Wikipedia page, GET would be the obvious choice. It could of course be some other request type such as HEAD or PUT, but that is not typical. You could always just var_dump($_SERVER['REQUEST_METHOD']);, load the page, and see for your self what it is. Ultimately you should not really worry as much about whether the page was sent via a POST or a GET, but instead focus on 'was the form submitted or not'. That is a question more easily answered by checking for specific form details rather than the request method. if (isset($_POST['someFieldInYourForm'])){ //form was submitted } else { //form was not submitted }
  12. Once you consider it to be solved you can mark it as solved. Others can still make replies if they have something else to add. I went ahead and marked it solved for you.
  13. Your question doesn't really make much sense to me. Why not just use sprintf exactly like you did in your 'something like this' example. $where = "WHERE SUBSTRING(name,1,1) = '%s' "; foreach($c as $v) { $sql = sprintf($where, $v); } Going back to your full mysql example: $conditions = array(); $where = "SUBSTRING(name,1,1)='%s' "; foreach($alternatives[$c] as $v) { $conditions[] = sprintf($where, $v); } $sql = 'blah blah WHERE '.implode(' OR ', $conditions);
  14. The point was that your query is invalid, both in the example and your code. A query can only have a single WHERE clause, not several joined together using ||. Also, since your using an OR condition, you can just use the IN clause in your query to make things easier. ex: WHERE SUBSTRING(name,1,1) IN ('a', 'b', 'c', ...) The value you put in the IN clause can be generated very easily via imploding an array of multiple possible values. You would just find your array of alternatives in the list and implode that and stick it into the in clause.
  15. The comments are fine. Your else block is unnecessary though, you could just remove it entirely. An if statement does not have to have a corresponding else.
  16. Your subquery should only select a single column, not *. However, you could probably do what you want better using a left join query instead. I took a guess that the column in test_picks that your matching with the username column in clp_user is also named username SELECT c.username FROM clp_user c LEFT JOIN test_picks t ON t.username=c.username AND t.t_id=3 WHERE ide != 1 AND t.username IS NULL
  17. A little. There are semantics behind GET and POST. Most requests are GET, as all your doing is requesting a document from the server basically. The server finds it and gives it to you. POST is used for when you need to send information to the server, and the server does something with that information such as save it do a db or modify a file or something, then it will return a result to you. The only way to do a POST request is via a <form method="post"> tag (or javascript + xhr). On a basic level, anything other than submitting form is likely a GET request. Submitting a form will depend on what the method attribute is set it, and it defaults to get. If you need to decide which method to use, do so based on whether the request will be modifying the data on your server. If all you'll be doing is serving up a static file, or only showing information from your db but not changing it, use a GET. If you'll be using the information submitted to make changes to your data, use a POST. Reading this page will give you more info about the methods and how they are intended to be used.
  18. I've heard some people say something along the lines of if you have more lines than fit on your screen in a function, it is too big. For me this would be around 60 lines. I do not necessarily agree with this, but there are advantages to attempting to keep the line count down. It's easier to debug things if you can see the whole body of a function at once rather than having to constantly scroll. Some times there is just nothing you can do though. I have a few functions where the SQL query itself consists of 100+ lines, then there is the code to process it on top of that. A whole class or script though will likely have many lines. If you feel like you have too much stuff in your script or function, break it out into other functions or include files at logical places. If you feel it is ok, then leave it as is. PHP doesn't care one way or the other, it's all about what you find to be the easiest to read, understand, and maintain. For example I had a function that registered users for courses in one script. The process of doing that involved creating an invoice, processing payment, and adding the course record to the db. All three steps together ended up being a lot of code so I broke it out into three separate functions. It makes the code more readable, and also cuts down on the indentation level so the code is closer to left of the screen. I have some scripts that have several thousand lines of code in them, and that's not even counting all the support files that have been include()'ed into it. Sometimes it just takes a lot of code to do what you need to do. The main thing if you want to try and keep the line count down is to just watch out to make sure your not repeating the same code over and over. If you are, turn it into a function or a loop so it can be easily reused. There are also ways you can restructure things sometimes to use less lines, such as using the ternary operator for short if/else conditions. Learning these things mainly just comes down to time and experience. Look at other peoples code as well as yours and get ideas from that. When I was just starting out I spent a lot of time browsing help forums such as this one. In the early days I did not participate much but I learned a lot just from reading other peoples problems and the solutions they were given. Even still I occasionally learn something new from reading other responses here.
  19. Kick off an XHR request to a php script on the server when the box is closed which will mark the end time.
  20. Maybe this configuration would do it: smtpd_sender_restrictions reject_unknown_sender_domain Not sure, far from any kind of a postfix expert. That is just the closest thing I could find when I searched the man page.
  21. When you echo the image name, your json string is no longer valid so your Javascript fails. You need to add the image name as another key in your json output. As for outputting json, I would suggest you store your info in an array then use json_encode to output it. It is far easier to use and manipulate the object before outputting it when you do that. $jsonArr = array( 'img' => $row['img'], 'status' => 1, 'id' => $row['id'], 'price' => $row['price'], 'txt' => ' <table width="100%" id="table_'.$row['id'].'"> <tr> <td width="60%">'.$row['name'].'</td> <td width="10%">$'.$row['price'].'</td> <td width="15%"><select name="'.$row['id'].'_cnt" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option></slect> </td> <td width="15%"><a href="#" onclick="remove('.$row['id'].');return false;" class="remove">remove</a></td> </tr> </table>' ); echo json_encode($jsonArr);
  22. I don't really know if a record like ns1 IN NS ns1.mydomain.com is needed. I'm not that familiar with NS records. I've only done a few basic dns configurations, and have not done that for quite a while. You would need an A record to define what ns1.mydomain.com resolves to. @ only covers the base domain, it does not act as a wildcard for all subdomains. For that you would use *. @ IN A xxx.xxx.xxx.xxx would point mydomain.com to that ip, but www.mydomain.com would still be non-existent and not resolve unless you define it or define *.
  23. It stands for the domain itself, without and subdomains. I think technically it is an alias for something defined elsewhere but I cannot remember the details at the moment. As a general case though, it representing the domain is true. In a zone file for mydomain.com: @ IN A 192.168.0.1 would mean that 'mydomain.com' points at that address.
  24. I have to agree with the site feeling too big. My laptop has a screen resolution of 1366x768, when I open the page the header seems to take up a little under 1/3 of the viewport, and your food image takes up the rest (and does not completely fit). Using chrome's zoom feature to scale it down makes it seem better. Knocking it down one notch (83% of normal) make a considerable difference. Two notches seems even better, but at that point it would probably be way to small on larger screens. Other than that, it looks good. I like the colors, the layout is simple and easy to navigate. Just needs some content now
  25. When your using sessions, each page that calles session_start will acquire a lock on the session's data file. As long as the script is running the session cannot be accessed by any other files until the lock is released which happens when the session is written out at the end of the script. Your download script is locking the session file, but it will not release it until the script ends which is when the download is complete. This means no other pages on your site which use the session will work for this duration of time. You can close the session manually using session_write_close in your script. Call this function just before you output your headers and the file data. That will release the session lock so the rest of the site will work while the file downloads.
×
×
  • 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.