Jump to content

HuggieBear

Members
  • Posts

    1,899
  • Joined

  • Last visited

Posts posted by HuggieBear

  1. Make sure your form has a username and password field and then use something like this:

     

    <?php
    
    session_start();
    
    if (!isset($_SESSION['logged_in'])){
       // You're not logged in, have you submitted the form
       if (isset($_POST['Submit']) {
          // You have submitted the form
          if ($_POST['username'] == 'admin' && $_POST['password'] == 'xyz'){
             // You're authenticated
             $_SESSION['logged_in'] = $_POST['username'];
             echo "Thanks for logging in";
          }
          else {
             // You entered invalid details
             echo "Sorry, the username and password you entered are invalid";
          }
       }
    }
    else {
       // You're already logged in
       echo "You're logged in as " . $_SESSION['logged_in'];
    }
    
    if (!isset($_SESSION['logged_in'])){
       // Display the form
       echo "This is where your form code goes";
    }
    
    ?>

  2. Fixed that too. Now Im getting this error:

     

    Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /mounted-storage/home7/sub007/sc30390-PTUD/***********.com/form2.php on line 31

     

    Why do you think that is?  Look at what I asked you to change (Connection variable name!)

  3. That means that your database connection failed, or you're specifying the wrong connection handle.  In your case it's the latter.

     

    Change:

    mysql_query($sql,$con)

     

    To:

    mysql_query($query,$connection)

     

    As those are the variable names you've used earlier in your script.

  4. If you're checking two variables, make sure it comes before you check one.

     

    e.g.

     

    if ($direction == 'north'){
       echo 'Direction is North';
    }
    elseif (($direction == 'north') && ($distance == '1')){
       echo 'Direction is North, Distance is 1';
    }

     

    The second condition will never be met as the first is less specific.  Put the most specific conditions first, like this:

     

    if (($direction == 'north') && ($distance == '1')){
       echo 'Direction is North, Distance is 1';
    }
    elseif ($direction == 'north'){
       echo 'Direction is North';
    }

  5. I'm trying to figure out if today's current date and time falls between Mon & Fri

     

    This doesn't make sense.  If you're trying to find out if today's date falls on a week day, what does the time matter?

     

    $weekend = array('Sat','Sun');
    $today = date('D');
    if (!in_array($today, $weekend)){
       echo 'Yup';
    }
    else {
       echo 'Nope';
    }

  6. Is the data in the text file delimited in anyway e.g. colon?

     

    1:J.K. Rowling:"Well, I had one that I was playing Quidditch the other night," said Ron, screwing up his face in an effort to remember. "What do you think that means?".  "Probably that you're going to be eaten by a giant marshmallow or something," said Harry, turning the pages of The Dream Oracle without interest.

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