Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. CaSe SeNsEtIvE
  2. If you want the iframe to adjust it's height to whatever page is loaded within it then you'll need Javascript of some sort, there is no pure HTML solution. jQuery would probably allow for the simplest solution. Also the content of the frame would probably have to pass the same-origin policy test.
  3. Because you used quotes around the expression, no math will be performed. At the end $time will contain (assuming $time originally contained 12345): 12345+3600, rather than 15945 as you intended. The value 12345+4600 is an invalid number and thus cannot be passed to the date function. So, remove all your quotes so that the math is performed and you get a real number. Unless you want something to be treated as a string, do not quote it.
  4. Make your where condition AND CONVERT(_sfm_form_submission_time,DATE)=CURRENT_DATE(). Then it will only compare the date portion and ignore the time.
  5. foreach ($_POST['uid'] as $id){ $hours = $_POST['hours'][$id]; echo "User {$id} has hours {$hours}<br>"; } You use the ID to index into the hours array and grab the value.
  6. $stmt = $mysqli->prepare("DELETE FROM races WHERE name = ? "); $stmt->bind_param("s", $horse); if ($stmt->execute()) { echo "You have deleted " . $horse; } else { echo "Failed to delete {$horse}<br>\r\n"; echo "[{$stmt->errno}] {$stmt->error}<br>\r\n"; } That should spit out any error that is preventing it from deleting.
  7. Then your doing something wrong. PDO is not noticeably slower than using mysql_* or MySQLi. Without you showing us your code though, there isn't anything we can do to help you.
  8. kicken

    Declair an id

    In order for something to be posted to a PHP page it has to be in a form element such as input, textarea, select, etc. If you just want a static value then use a hidden input to send it. Something like this, if you want the user to see something in addition to it being posted: <div><input type="hidden" name="TABLE" value="DEBITS">DEBITS</div>
  9. Your code only attempts to read a single line from the socket, but a command could generate several response lines. EHLO typically will generate a few as it lists out various extensions that are available. If you want to properly manage an SMTP session and read/validate the responses to your commands then you need to spend a lot more time on your socket handling. A simple fgets/fputs will not suffice. Use the streams api to handle your socket connection. You'll want to toggle on non-blocking mode and then use a loop around steam_select for reading the socket data. It is possible you'll only read a partial line on any given socket read so you need to append data to a buffer, not process it directly For processing, extract a full line from that buffer and parse it's contents. Determine what actions need to be taken for the given response and do them. If you don't want to go through all that hassle, use an existing project like PHPMailer or SwiftMail. If you do want to do it, for learning or whatever, make an attempt w/ the above and post back if you need more help.
  10. Have index.php define a constant, and inside content.php check if that constant has been defined. Of not, redirect. Index <?php define('IN_INDEX_PHP', true); include('content.php'); Content <?php if (!defined('IN_INDEX_PHP')){ header('Location: index.php'); exit; }
  11. Your linux host is quite unlikely to have a file.exe program for you to run. It may have a file (no .exe) program though, if that is what you're after. Windows and linux have different programs w/ different naming schemes. You need to make sure your exec call matches the target system's naming scheme and references a valid program.
  12. Use mod re-write. Depending on how complex the change(s) are you can either do it strictly w/ mod re-write or via an intermediary php script. For the given example, something such as this should do the trick: RewriteEngine On RewriteRule ^/buy-now/(\w+)/order/(\d+)$ /buy-now/order/$1/$2 [R=301] You may need to tweak the regex, I didn't test it at all. Once the regex is correct though, that will issue a permanent redirect for the old URL format to the new URL form.
  13. There are various ways to accomplish the validation. You can use trim and a comparison to the empty string to check if it was not provided. You could learn some basic regular expressions and use preg_match to match the required format. Another way to match the format would be a combination of explode, ctype_digit and strlen.
  14. Loosely typed means the language will automatically convert data from one type to another in order to accomplish what needs done. In a strictly typed language you would have to manually convet the data to the appropriate type. Being loosely typed has some nice benefits of not having to code a bunch of extra stuff just to convert types, and generally makes it easier to work with. It can also however introduce issues if the conversion doesn't happen as one might expect. There are some notable examples of this in PHP, such as: 0 == "true" is true, because "true" gets convert to an integer(0) then you have 0==0. "1987654321987654321" == "1987654321987654321827" might be true, depending on if you have a 32-bit or 64-bit version of PHP. Because both strings are purely numeric PHP converts them to numbers and compares them, but on a 32-bit system the numbers are too large and end up being the same after conversion. The above, and other potential issues is why the === operator exists which prevents PHP from doing a type conversion. Mostly though, if your function is going to return something at all, it should always return something. Returning a value on success but nothing on a failure is bad practice, even if it ends up working in PHP. By explicitly returning false then areas using that function can determine for sure if something failed vs just getting back a false-like value. For a boolean function (one that returns either true or false) it's not that big of an issue but if your function returns say an integer normally, there is potential for a valid return value (0) to be considered false. For instance, strpos returns an index on success (and 0 is a perfectly valid index) or false on false.
  15. There are some projects out there that will render a website to an image. Do a little googling and you can find them. Once you have one installed just have PHP exec the program with the proper parameters to capture the URL you want.
  16. What the user sees as who the message is from comes from the From: header, which you can see being set in the sample code. if(mail ($email, $emailsubject, $body, "From: $fromname <$fromemail>")) //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Right there.
  17. kicken

    PHP Classes

    That is why the SQLite project/extension exists. If you want to try and re-create such a thing be my guest, just be aware that such things already exist on a much more functional level.
  18. In my particular case it just does a second query and then merges the results together in the code. Ie: public static function GetDetails($id, $loadEnrollments=false){ $stmt = /* query to get basic details */; $details = $stmt->fetchAll(); if ($loadEnrollments){ $stmt = /* query to get enrollment data */ $details['enrollments'] = $stmt->fetchAll(); } return $details; } Depending on your needs though you could do anything from just change an array of fields to be selected to simply using two different querys. $fields = array('a','b','c'); if ($loadEnrollments){ $fields=array_merge($fields, array('d','e','f')); } //or if ($loadEnrollments){ $sql = 'The big query'; } else { $sql = 'The smaller query'; } $stmt = $db->query($sql);
  19. The $em variable would hold an instance of something known as an Entity Manager. That is basically a class that knows about your different entities (Users, Messages, Blogs, Photos, whatever) and handles the creation of those entities. Something like $em->find('User', 1) would be asking the entity manager that you want it to find the User entity with ID #1 so what it would do is generate the appropriate query to pull the information from the database, create a new instance of the User class, and then set all the properties of that class with the values from the database. How it knows what to do generally comes down to two possibilities: A) Everything follows a strict naming standard. Your class names match up with your table names. Your property names match up with your column names. And so on for any other cases B) or everything is configured via some configuration file which defines which entities your application has, what class is used to represent them, which properties match up with with columns, etc. The second approach is more flexable generally but also more work in the initial setup. Often there is a script you can use that will apply the principals of method a to automatically generate a configuration for method b which can then be tweaked if necessary. The point is about having consistant interfaces and being able to use them easily. In the example above, there is some class that is used for sending email messages between users. It accepts two User objects and the message as it's parameters and then acquires the user's email (and potentially other details, ie user ID, names, etc) from those user objects by calling the appropriate properties (ie, $from->getEmail, $from->getName, etc). By having your code always deal with user objects you then always have a nice consistant way to access a users data. One prime example of not needing a database would be if you do Unit Testing. In such an environment you would create "fake" data and use that to do the test. So in the example you'd create two User objects with fake details and pass that to your messaging object in order to test that it is working properly. Rather than go through a huge hassle of setting up a DB and anything else that might be neccessary for that to work you just create two simple objects, set their details, and go. Now, all of that said/explained: Our application is similar to what you have said where we have methods that return an array of all the various information for a given entity. For the most part I've gone the route of using a single method, GetDetails, with parameters to control which information to load. For example we have a Student class that returns details about a student. Whether it loads additional details about their enrollments though is a parameter. The method is defined as public static function GetDetails($studentId, $loadEnrollments=false); When all we need is things like their name, email, etc then we skip loading the enrollments. If we need the enrollment data then we just set the second parameter to true in order to have it pull that information as well. As far as which is best, separate methods vs parameters, it doesn't really matter. Either will work fine, neither is really fantastic. Something more advance like describe in previous posts would likely be best just from a maintainability/testability point of view, which is the most important point of view.
  20. There is also strtr that may work for what you need to do.
  21. Yes. Try it. The problem with your original was that it assumed the username was in the first/second element. This version makes no such assumption.
  22. see also: https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
  23. This: <?php $host = $_SERVER["HTTP_HOST"]; if (strncmp($host, "www.", 4) == 0) { $host = substr($host, 4); } $baseDomain = '.mysite1234.com'; $baseLen = strlen($baseDomain); if (substr_compare($host, $baseDomain, -$baseLen) == 0) { $host = substr($host, 0, -$baseLen); } An alternative non-regex solution, going back to explode, would be: $host = explode('.', $_SERVER["HTTP_HOST"]); if ($host[0] == 'www') array_shift($host); //Remove the base domain. This assumes your base domain contains only one dot (example.com) rather than two (example.co.uk) $host = array_slice($host, 0, -2); $username = implode('.', $host);
  24. You shouldn't be running mysql_real_escape_string on a variable unless it is going into a query. Running it on everything like that causes as many problems (or more) as it solves. As you pointed out, you have to undo it when you want to output the variable to the screen, just as one example. if you want to avoid typing out mysql_real_escape_string a bunch of times, wrap up your escaping into another function with a shorter name. Maybe do a sprintf() like function. untested example: function prep_query(/*...*/){ $args = func_get_args(); foreach ($args as $i=>$v){ if ($i==0) continue; //skip sql text if (get_magic_quotes_gpc()) $v=stripslashes($v); $args[$i] = mysql_real_escape_string($v); } return call_user_func_array('sprintf', $args); } echo prep_query("SELECT * FROM blah WHERE username='%s' AND IsSomething=%d", $_GET['username'], $_GET['something']);
  25. You could also just boot into windows safe mode and delete the file. Mysql shouldn't be started up when you boot into safe mode.
×
×
  • 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.