Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    M'sia
    Posts
    4

    Unanswered: prompt for username and password

    Hi, I'm new in PHP, and i'm trying to make a guestbook using PHP and MySQL.
    I'm having problem on making a page (delete.php) to delete records from my guestbook.
    In delete.php, i'm thinking of doing something like this:
    when the user enter delete.php,they will just see a form asking for username and password.After the right username and matching password is entered, the records of the guestbook will be listed out in the same page (in delete.php), so that people cannot access the delete page by just typing the url (http://..../delete.php). is it possible to do it this way?if it is possible,how do i do it?
    i tried soing something like these,but it doesn't work.

    PHP Code:
    <?php

    include ('header.php');

    echo 
    '<h2>Please Login to delete records.</h2>';
    echo 
    '<form action="$PHP_SELF" method="post"><table border="0">';
    echo 
    '<tr><td><b>Username :</b><br></td>';
    echo 
    '<td><input type="text" name="username" size="20"></td></tr>';
    echo 
    '<tr><td><b>Password :</b><br></td>';
    echo 
    '<td><input type="text" name="password" size="20"></td></tr>';
    echo 
    '<tr><td><input type="submit" name="login" value="Login!"></td></tr>';


    if(
    $login)
    {
        
    $username=$HTTP_POST_VARS['username'];
        
    $password=$HTTP_POST_VARS['password'];
        

        
    $query="Select password from guestbook_admin where username='".$username."'";
        
    $result=mysql_query($query);
        
    $row mysql_fetch_array($result);
        if(
    $row['password']==sha1("$password"))
        {
            echo 
    '<h2>View my guest book</h2>';
              echo 
    '<br /><br />';
              
    $result=mysql_query("select * from guestbook ")
            or die(
    mysql_error());
     
            
    $num_results mysql_num_rows($result);

       
             for (
    $i=0$i <$num_results$i++)
              {
                 
    $row mysql_fetch_array($result);
                      echo 
    '<table><tr><td><b>Name : </b></td>';
                      echo 
    '<td>';
                echo 
    $row['name'];
                echo 
    '</td></tr>';
                echo 
    '<tr><td><b>location : </b></td>';
                      echo 
    '<td>';
                echo 
    $row['location'];
                echo 
    '</td></tr>';
                echo 
    '<tr><td><b>E-mail : </b></td>';
                      echo 
    '<td>';
                echo 
    $row['email'];
                echo 
    '</td></tr>';
                echo 
    '<tr><td><b>URL : </b></td>';
                      echo 
    '<td>';
                echo 
    $row['url'];
                echo 
    '</td></tr>';
                echo 
    '<tr><td><b>Comments : </b></td>';
                      echo 
    '<td>';
                echo 
    $row['comments'];
                echo 
    '</td></tr>';
                echo 
    '<tr><td valign="top" align="right"><b>Delete entry?</b></td>';
                echo 
    '<td valign="top" align="left">
                     <input type=checkbox name="entry_id[]" value="{$row["entry_id"]}">'
    ;
                echo 
    'Yes,delete entry #{$row["entry_id"]}</td></tr></table><br>';
            }
        }
        
      }
    thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    you can use .htaccess to make one of those javascript prompt things come up.
    Mr. Lars

  3. #3
    Join Date
    Mar 2004
    Location
    M'sia
    Posts
    4
    thanks for the suggestion.
    But i don't know javascipt..=(
    is there any other way to do it?
    using PHP or HTML?

  4. #4
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    it doesnt involve knowing javascript. If you have cpanel you can do it. "Password Protect Directories" I think.
    Mr. Lars

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •