Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by AyKay47

  1. Not the best of solutions, as now the bots doesn't even have to guess: They can just read the correct answer from the HTML code directly...

    Nonsense.

     

    Using both a hidden input and a session is a bit of overkill here. Storing the value in a session will be fine.

     

    <?php
    session_start();
    // create an anti-spam calculation to be answered
    $first_num = rand(1, 3);
    $second_num = rand(1, 3);
    $multiplier = rand(2,3);
    
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
    if($_POST['user_answer'] !== $_SESSION['actual_answer']) {
    echo "You didn't answer the anti-spam calculation correctly.";
    } else {
    echo "Correct!";
    }
    } else {
    $_SESSION['actual_answer'] = ($first_num + $second_num) * $multiplier;
    
    
    ?>
    <form method='post' action=''>
    <?php echo "($first_num + $second_num) x $multiplier) = "; ?>
    <input type='text' name='user_answer' id='user_answer' /><br /><br />
    <input type='submit' name='submit' value='go' />
    </form>
    <?php
    }
    

  2. The only thing I can think of for the code Pikachu posted is that there are 8 possible values for $_FILES[]['error'] and the OP has 7 in the switch. But even so, $error_msg should output the error value, the default switch value should output as well, something. That's what initially jumped out at me as well when reading the code.

  3. Code is run from top to bottom. You're checking if a password and username have been set and telling it to echo that before anyone gets a chance to enter any data.

     

    What? the OP has the error code inside of a condition that waits for the edit button to be clicked.

     

    davidolson, the code is doing exactly what you have coded it to do, what are you expecting it to do?

  4. num_rows is assumed a constant, you are after mysql_num_rows()

    The second error is being triggered because, again, you are using $result as if it is an object, it's not:

     

    if(mysql_num_rows($result) >= 2)
    {
     $email = 'mymail@gmail.com';
     $subject = "LOW STOCK WARNING!";
     $message = 'One or more products are running low:\r\n';
     while($row = mysql_fetch_assoc($result))
     {
       $message .= $row["product_id"] . "\r\n";
     }
     if(mail($email, $subject, $message))
     {
       //mail successfully sent
     }
     else
     {
       //mail unsuccessful
     }
    }

  5. If you debug your code correctly, you will not need to ask us why something isn't working, error handling will tell you.

    You are treating $result as if it were an object, when in fact its a mysql resource.

     

    Edit: to simply answer the question above:

    $result = mysql_query() or die(mysql_error())
    

  6. add Parentheses () to tell sql how to evaluate it...

     

    $instclasses = mysql_query("SELECT * FROM people where pid='$doin[pid]' OR (cpid='$doin[pid]' AND pid='$_POST[cpid]') OR cpid='$_POST[cpid]'");
    

     

    not sure if this is your intent, but you get the idea of using the "()" to control the grouping

     

    The OP is using () already in his second post.

    Also OP, we cannot tell you whether or not the query is correct for what you are trying to do without knowing what you are trying to do.

  7. list() assigns the values from right to left, however the only time you actually need to worry about that is when you pass arrays with indices into the function. The OP is using list() correctly here. Refer to php.net Example#1.

     

    White_lily I ask what debugging steps you have taken because we need to know exactly where this code is failing. If you have "echoed all variables possible for values" then you should know where the code is failing. What is the value of $propicmargin? Add a condition to determine whether getimagesize() is working correctly:

     

    $size = getimagesize($propicmargin);
    if(!$size)
    {
     die("Could not find the size of file:<br />" . $propicmargin);
    }
    

     

    If the above code passes, $width and $height will be assigned values.

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