DB User authentication.

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default DB User authentication.

    Not a programmin newbie, but a PHP newbie.

    I'm working off the user authentication and database thing off
    hotscripts.com.

    It doesn't work, yet from what I can see, it should.

    Maybe I've done something wrong (no wait... obviously I've done something
    wrong)

    Any help?
    Here are the contents of the relevant files:

    INDEX.HTML:
    <form name="form1" method="post" action="register.php">
    <p>First Name
    <input name="first_name" type="text" id="first_name" value="">
    <br>
    Last Name
    <input type="text" name="last_name" value="">
    <br>
    Email Address:
    <input type="text" name="email_address" value="">
    <br>
    Username:
    <input type="text" name="username" value="">
    <br>
    Info:
    <textarea name="info"></textarea>
    <br>
    <input type="submit" name="Submit" value="Join">
    </p>
    </form>





    REGISTER.PHP

    <?
    include 'db.php';

    //define variables
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email_address = $_POST['email_address'];
    $username = $_POST['username'];
    $info = $_POST['info'];

    $first_name = stripslashes($first_name);
    $last_name = stripslashes($last_name);
    $email_address = stripslashes($email_address);
    $username = stripslashes($username);
    $info = stripslashes($info);

    echo $first_name . "<br>";
    echo $last_name . "<br>";
    echo $email_address . "<br>";
    echo $username . "<br>";
    echo $info . "<br>";

    /* if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
    echo 'You did not submit the following required information! <br />';
    if(!$first_name){
    echo "First Name is a required field. Please enter it below.<br />";
    }
    if(!$last_name){
    echo "Last Name is a required field. Please enter it below.<br />";
    }
    if(!$email_address){
    echo "Email Address is a required field. Please enter it below.<br
    />";
    }
    if(!$username){
    echo "Desired Username is a required field. Please enter it
    below.<br />";
    }
    include 'index.html'; // Show the form again!
    exit(); // if the error checking has failed, we'll exit the script!
    }*/

    $sql_email_check = mysql_query("SELECT email_address FROM users WHERE
    email_address='$email_address'");
    $sql_username_check = mysql_query("SELECT username FROM users WHERE
    username='$username'");

    $email_check = mysql_num_rows($sql_email_check);
    $username_check = mysql_num_rows($sql_username_check);

    if($email_check > 0 || $username_check > 0) {
    echo "There were some errors: <br>";
    if($email_check > 0) {
    echo "email taken";
    unset($email_address);
    }
    if($username_check > 0) {
    echo "username taken";
    unset($username);
    }
    include 'index.html';
    exit();
    }

    function makeRandomPassword() {
    $salt = "abcdefghijklmnopqrstuvwxyz1234567890";
    srand((double)microtime()*1000000);
    $i = 0;
    while ($i <= 7) {
    $num = rand() % 33;
    $tmp = substr($salt, $num, 1);
    $pas = $pass . $tmp;
    $i++
    }
    return $pass;
    }

    $random_password = makeRandomPassword();

    $db_password = md5($random_password);

    $info2 = htmlspecialchars($info);
    $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address,
    username, password, info, signup_date) VALUES ('$first_name, $last_name,
    $email_address, $username, $password, $info2, now())" or die
    (mysql_error());

    if ($sql) {
    echo "bugger";
    } else {
    $userid = mysql_insert_id();
    $subject = "membership, foo";
    $message = "Dear $first_namae $last_name,
    To activate you membership, click here:
    [url]http://[[/url][domain]]/dbtest/activate.php?id=$userid&amp;code=$db_password
    Thanks!";
    mail($email_address, $subject, $message, 'From: Yep-MM test Server\n
    X-Mailer: PHP/' . phpversion());
    echo "Done.";
    }
    ?>



    DB.PHP
    <?
    $hostname = "localhost";
    $database = "[[dbname]]";
    $username = "[[username]]";
    $password = "[[password]]";
    $connection = mysql_pconnect($hostname, $username, $password) or
    die(mysql_error());
    ?>


    Allan Hugo Guest

  2. Similar Questions and Discussions

    1. user authentication weirdness
      On our development machine, running MySQL 5.0.19, I created a database alert_db, and for development purposes created a user called alert_db with a...
    2. User Authentication
      Hi All: I would like to have certain areas of a site that I am developing password protected but I am not sure how to go about doing this. I know...
    3. User Authentication problems
      hi everyone i am using a php site and i have been trying to implement user authentication by completing the macromedia tutorial "Macromedia -...
    4. XP user authentication
      Folks, Given the following function signature: bool AutheticateUser(string uid, string pwd); Can anyone tell me which .Net class.function API...
    5. SQL User authentication
      Is it possible to authenticate user using a SQL database, containing users and passwords? What I want to achive is: I have as SQL database...
  3. #2

    Default Re: DB User authentication.

    Allan Hugo wrote:
    >
    > Not a programmin newbie, but a PHP newbie.
    >
    > I'm working off the user authentication and database thing off
    > hotscripts.com.
    >
    > It doesn't work, yet from what I can see, it should.
    >
    > Maybe I've done something wrong (no wait... obviously I've done something
    > wrong)
    >
    > Any help?
    > Here are the contents of the relevant files:
    >
    > INDEX.HTML:
    > <form name="form1" method="post" action="register.php">
    > <p>First Name
    > <input name="first_name" type="text" id="first_name" value="">
    > <br>
    > Last Name
    > <input type="text" name="last_name" value="">
    > <br>
    > Email Address:
    > <input type="text" name="email_address" value="">
    > <br>
    > Username:
    > <input type="text" name="username" value="">
    > <br>
    > Info:
    > <textarea name="info"></textarea>
    > <br>
    > <input type="submit" name="Submit" value="Join">
    > </p>
    > </form>
    >
    > REGISTER.PHP
    >
    > <?
    > include 'db.php';
    >
    > //define variables
    > $first_name = $_POST['first_name'];
    > $last_name = $_POST['last_name'];
    > $email_address = $_POST['email_address'];
    > $username = $_POST['username'];
    > $info = $_POST['info'];
    >
    > $first_name = stripslashes($first_name);
    > $last_name = stripslashes($last_name);
    > $email_address = stripslashes($email_address);
    > $username = stripslashes($username);
    > $info = stripslashes($info);
    >
    > echo $first_name . "<br>";
    > echo $last_name . "<br>";
    > echo $email_address . "<br>";
    > echo $username . "<br>";
    > echo $info . "<br>";
    >
    > /* if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
    > echo 'You did not submit the following required information! <br />';
    > if(!$first_name){
    > echo "First Name is a required field. Please enter it below.<br />";
    > }
    > if(!$last_name){
    > echo "Last Name is a required field. Please enter it below.<br />";
    > }
    > if(!$email_address){
    > echo "Email Address is a required field. Please enter it below.<br
    > />";
    > }
    > if(!$username){
    > echo "Desired Username is a required field. Please enter it
    > below.<br />";
    > }
    > include 'index.html'; // Show the form again!
    > exit(); // if the error checking has failed, we'll exit the script!
    > }*/
    >
    > $sql_email_check = mysql_query("SELECT email_address FROM users WHERE
    > email_address='$email_address'");
    > $sql_username_check = mysql_query("SELECT username FROM users WHERE
    > username='$username'");
    >
    > $email_check = mysql_num_rows($sql_email_check);
    > $username_check = mysql_num_rows($sql_username_check);
    >
    > if($email_check > 0 || $username_check > 0) {
    > echo "There were some errors: <br>";
    > if($email_check > 0) {
    > echo "email taken";
    > unset($email_address);
    > }
    > if($username_check > 0) {
    > echo "username taken";
    > unset($username);
    > }
    > include 'index.html';
    > exit();
    > }
    >
    > function makeRandomPassword() {
    > $salt = "abcdefghijklmnopqrstuvwxyz1234567890";
    > srand((double)microtime()*1000000);
    > $i = 0;
    > while ($i <= 7) {
    > $num = rand() % 33;
    > $tmp = substr($salt, $num, 1);
    > $pas = $pass . $tmp;
    > $i++
    > }
    > return $pass;
    > }
    >
    > $random_password = makeRandomPassword();
    >
    > $db_password = md5($random_password);
    >
    > $info2 = htmlspecialchars($info);
    > $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address,
    > username, password, info, signup_date) VALUES ('$first_name, $last_name,
    > $email_address, $username, $password, $info2, now())" or die
    > (mysql_error());
    >
    > if ($sql) {
    > echo "bugger";
    > } else {
    > $userid = mysql_insert_id();
    > $subject = "membership, foo";
    > $message = "Dear $first_namae $last_name,
    > To activate you membership, click here:
    > [url]http://[[/url][domain]]/dbtest/activate.php?id=$userid&amp;code=$db_password
    > Thanks!";
    > mail($email_address, $subject, $message, 'From: Yep-MM test Server\n
    > X-Mailer: PHP/' . phpversion());
    > echo "Done.";
    > }
    > ?>
    >
    > DB.PHP
    > <?
    > $hostname = "localhost";
    > $database = "[[dbname]]";
    > $username = "[[username]]";
    > $password = "[[password]]";
    > $connection = mysql_pconnect($hostname, $username, $password) or
    > die(mysql_error());
    > ?>
    What do you mean by "doesn't work"? Please describe any error messages you're
    getting, or other indications that it is not working correctly.

    Shawn
    --
    Shawn Wilson
    [email]shawn@glassgiant.com[/email]
    [url]http://www.glassgiant.com[/url]
    Shawn Wilson Guest

  4. #3

    Default Re: DB User authentication.


    "Shawn Wilson" <shawn@glassgiant.com> wrote in message
    news:3FA67685.294A0C9D@glassgiant.com...
    > Allan Hugo wrote:
    > >
    > > Not a programmin newbie, but a PHP newbie.
    > >
    > > I'm working off the user authentication and database thing off
    > > hotscripts.com.
    > >
    > > It doesn't work, yet from what I can see, it should.
    > >
    > > Maybe I've done something wrong (no wait... obviously I've done
    something
    > > wrong)
    > >
    > > Any help?
    > <snip>
    > What do you mean by "doesn't work"? Please describe any error messages
    you're
    > getting, or other indications that it is not working correctly.
    what do i mean by 'doesn't work'?

    well i get a white page...


    Allan Hugo Guest

  5. #4

    Default Re: DB User authentication.

    On Tue, 04 Nov 2003 00:07:26 GMT, Allan Hugo wrote:
    >
    > "Shawn Wilson" <shawn@glassgiant.com> wrote in message
    > news:3FA67685.294A0C9D@glassgiant.com...
    >> Allan Hugo wrote:
    >>>
    >>> Not a programmin newbie, but a PHP newbie.
    >>>
    >>> I'm working off the user authentication and database thing off
    >>> hotscripts.com.
    >>>
    >>> It doesn't work, yet from what I can see, it should.
    >>>
    >>> Maybe I've done something wrong (no wait... obviously I've done
    > something
    >>> wrong)
    >>>
    >>> Any help?
    >> <snip>
    >
    >> What do you mean by "doesn't work"? Please describe any error messages
    > you're
    >> getting, or other indications that it is not working correctly.
    >
    > what do i mean by 'doesn't work'?
    >
    > well i get a white page...
    what do i mean by 'try and help yourself a little more'?

    Try using the same debug process that you do in any other language.
    Add some echo commands to see where the process is failing, and ask
    something a little more specific than "please debug my whole program" :)

    Cheers,
    iGadget
    iGadget Guest

  6. #5

    Default Re: DB User authentication.

    In article <9Tppb.176838$bo1.114413@news-server.bigpond.net.au>,
    [email]someone@microsoft.com[/email] says...
    > Not a programmin newbie, but a PHP newbie.
    >
    > I'm working off the user authentication and database thing off
    > hotscripts.com.
    >
    > It doesn't work, yet from what I can see, it should.
    Can you be a little more specific about 'doesn't work' - do you mean it
    lays on the couch all day drinking beer? Or is there some sort of error
    message? Or...
    > Maybe I've done something wrong (no wait... obviously I've done something
    > wrong)
    >
    > Any help?
    > Here are the contents of the relevant files:
    >
    > INDEX.HTML:
    <SNIP> lots of code
    As a debugging aid, you might consider using mysql_error after all calls
    to the db, and also echo your queries to ensure you are submitting the
    query you think you are.

    Cheers
    --
    Quod subigo farinam

    $email =~ s/oz$/au/o;
    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet?
    David Robley Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139