Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by AyKay47

  1. Something that I like to do is wrap array indices in curly braces when using double quotes.

     

    echo "<option value=\"{$row['state']}\">{$row['state']}</option>";

     

    I'm too lazy to concatenate all of the time, improves readability though.

  2. So the form is sending the data to the executing page?

    If so, simply action='' is fine in the form.

    You'll want something like this..

     

    if(isset($_POST['submit'])) //make sure submit button has been clicked
    {
        $gender = $_POST['gender']; //radio button value
        $first_age = $_POST['first_age']; //dd value
        $second_age = $_POST['second_age']; //dd value
        $sql = "select fields from table where something = '$gender' and something_else = '$first_age' and something_else = '$second_age'";
        //etc...
    }

     

    keep in mind that this is pseudo code providing a very basic example without the proper error checks etc..

  3. Also on that note, AyKay47, would you mind telling me the ideal alternative to passing the errors through the session? They have to be carried from one PHP file to another; would the alternative be logging IP session keys with error messages in the database then simply removing them once they are displayed?

     

    Typically errors are triggered within the executing script, so they don't need to be saved.

    However, if this is necessary, use $_SESSION's

  4. then $_SESSION['GORB']['message'] has been defined as a string, not an array.

    You can't "push" values onto a string.

    Posting the relevant code would help.

     

    Also, I wouldn't use the $_SESSION superglobal array to store simple errors, complete waste of resources.

  5. If the SQL is a static string that has absolutely no user data effecting it at all, then SQL injection is not possible.

    Say that you are building a query to use in PDO, but you are using a variable to determine which table to select from, and that variable comes from user data. This means that if you do not escape this user data, then the SQL query can be polluted and SQL injection is still possible even though you are using PDO.

    If the SQL query is clean, then you are good to go.

  6. Sorry to jump in on this one. But on the subject of PDO - is it right that it automatically escapes all your data so you don't need to mysql_real_escape_string ?

     

    To expand this a little further, the basic logic is to escape all user data before inserting into a db using your RDBMS escape string function, and to use htmlentities() upon grabbing data from a db. This converts things like quotes etc into their HTML entities before being executed. IMO, the safest way to work with databases is to use PDO, which separates the SQL and the user data.

     

    no, it executes the SQL and the PHP data separately, so escaping isn't an issue.

    If you need a further explanation, read here

  7. To expand this a little further, the basic logic is to escape all user data before inserting into a db using your RDBMS escape string function, and to use htmlentities() upon grabbing data from a db. This converts things like quotes etc into their HTML entities before being executed. IMO, the safest way to work with databases is to use PDO, which separates the SQL and the user data.

  8. Well I wish I could help further, but Im having trouble wrapping my head around what it is exactly that you are trying to do.

    The code I provided sets var dataOut to the Ajax response string. You can do whatever you want with this string.

    So I'm not really sure why you are having further issues.

  9. It used to default to the HTML view, then was changed to the Source view. Now with the new design it is back to the HTML view.

     

    I have always just forced a plain text output from within the code, with things like header("Content-Type: text/plain") or ini_set("default_mimetype", "text/plain").

     

    yeah, I have started to do the same now. thanks Sal

  10. it does this because in the pattern it is looking for a forward slash, which will only occur in pages inside sub-folders.

     

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} \.php -f
    RewriteRule ^(.*)$ $1.php

  11. well, the code I posted is the "proper" way to handle an ajax request.

    var dataOut is set to the ajax response string, so you can use that variable in whatever way you want, be it function calls etc.

    Which really brings us full circle, you can do something like what you were in the OP, minus the success: param, which doesn't exist inside of a normal function.

     

  12. what does writeOut do?

    this is what I'm thinking, you can tinker with it to suit your code:

     

    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          }
        }
      }
    xmlHttp.onreadystatechange = function(){
         if(xmlHttp.readyState == 4){
             dataOut = xmlHttp.responseText;
             var ajaxDisplay = document.getElementById("dispDiv");
             ajaxDisplay.innerHTML = dataOut;
         }
    };
    xmlHttp.open("GET", "data.php", true);
    xmlHttp.send(null);
       

     

    Of course, I always recommend you use jquery's AJAX API..  :P

×
×
  • 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.