Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by AyKay47

  1. So, what you suggest me to correct? Its good you are telling me my mistakes...as I want to correct myself...

     

    The FILTER_VALIDATE_INT is doing its job well, I tested it... Huhh, for the striplashes, I have heard that turning Magic_gp ON is not recommended. For the '@', I see that doing that would not display the line if an error occurs. Well, I have learnt all of these in PHPAcademy, you know that guy who always do tutorials on YouTube...

     

    Please, suggest me one by one about which to correct... and what I should do.... Thank you for telling my erros..its important to me to learn

     

    Pika has kindly laid out a list of things that should be done differently for you.

    Take the time to research each of these things and solve them yourself.

  2. I tried this, but nothing:

     

    mysql_query("UPDATE prices SET price1='".$price1."', price2='".$price2."', date='".$date."' WHERE id='".$id."' ");

     

    Would I have to declare each value or just the ones I need updated?

     

     

    You would declare only the field values that you want to update.

    If this is not working for you, add a little debugging.

     

    $sql = "UPDATE prices SET price1='$price1', price2='$price2', date='$date' WHERE id='$id'";
    mysql_query($sql) or die($sql . "<br />" . mysql_error());

  3. How do I make a reg expression for email validation? This is what I have:

     

    /(\da-zA-Z)+@(\da-zA-Z)+\.(a-ZA-Z)+/

     

    So it says, check one or more of digits, alphabets, followed by @, followed by one or more digits,alphabets, followed by '.', followed by one or more alphabets, but it's not working. I'm using a forms plugin in WordPress, and we have to enter our own reg expressions.

     

    Any help for my approach is appreciated.

     

    That is not what that regex says at all. You do not have your characters grouped in character classes. [a-zA-Z\d]

    The regex that you have is not doing what you think it is, and no valid email will pass that.

  4. \d = digits [0-9]

    [a-zA-Z] = letters (case insensitive)

    [\s\t] = white space (matches a space and tab respectfully)

    [^\s\t] = non-white space (matches anything other than the above white space characters)

     

    what does this have to do with your original question?

  5. ... but that involves reading ... ;D

     

    but you referred the OP to articles, which involve more reading. Reading is an important factor in learning.

    Yes this is caused by output being sent to the browser before setcookie() is being called. If there is no "seen" output being sent, the text editor you are using could be using a BOM (Byte Order Mark) for encoding.

  6. well, without the string ending anchor. A string like ",hey whats up" would match. If you want the alphanumeric character preceded by the comma to be the only match, then yes you need the ending anchor.

  7. then this condition:

     

    if(mysql_num_rows(mysql_query($verify)) != 0)
    {
    echo '<p class="fail">This email or username is already taken!</p>';
    }

     

    is returning FALSE, for some reason. The values are not comparing correctly to the values in the databse. Echo your SQL statement and verify the values.

     

    if(mysql_num_rows(mysql_query($verify)) != 0)
    {
        echo '<p class="fail">This email or username is already taken!</p>';
    }
    else
    {
        echo $verify;
        exit;
        //rest of code will not get executed
    }

  8. 1. escape all user data before using in an SQL statement using mysql_real_escape_string (assuming your db server is MySQL). This will prevent SQL injection and XSS. however it is preferred to use PDO with prepared statements.

     

    2. Do not use $_SERVER['PHP_SELF'] as a forms action, this will leave your forms open to XSS.

     

    3. Make sure files and directories have the proper permissions so user cannot view and/or tamper with them.

     

    There is a list of things that you can do for added security, I'm sure other users will list more. I will leave you with some reading from php.net on the security subject: http://php.net/manual/en/security.php

  9. This is probably what you want:

     

    <?php
    
    $string = '<b>Age:</b> 16';
    
    if (preg_match('~<b>Age:</b> (\\d+)~', $string, $match)) {
        echo ((int)$match[1] < 18) ? 'minor' : 'adult';
    }
    
    ?>
    

     

    no.

    If you are not sure of the age data and you need a tight regex you can use this.

     

    $string = '<b>Age:</b> 16';
    
    if (preg_match('~^<b>Age:</b> ([1-9][0-9]?|10[0-5])$~', $string, $match)) { //max age 105
        echo ((int)$match[1] < 18) ? 'minor' : 'adult';
    }

     

    else, if you are sure of the data, you can use this:

     

    $string = '<b>Age:</b> 16';
    
    if (preg_match('~^<b>Age:</b> (\d{1,3})$~', $string, $match)) {
        echo ((int)$match[1] < 18) ? 'minor' : 'adult';
    }

     

    or even:

     

    $pattern = '^<b>Age:</b> (\d+)$';

     

    curious, where are you getting the contents of $line?

  10. Hey AyKay47 what do you mean by debuging it.

     

    do you mean by using this

     

    ini_set("display_errors", "1");error_reporting(-1);

     

    I just used this just now for the first time. so not sure what all it really displays, but im assuming it displays any errors and even if you start a variable out with _

     

    how does everyone handle this. Should i just keep this on every page so its always active? Is that what most people do?

     

    yes, follow what PFM said. In this case, if the OP had the error settings correct, he should have received an "undefined variable" error and an invalid handle error.

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