DB User authentication.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan Hugo

    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="registe r.php">
    <p>First Name
    <input name="first_nam e" type="text" id="first_name " value="">
    <br>
    Last Name
    <input type="text" name="last_name " value="">
    <br>
    Email Address:
    <input type="text" name="email_add ress" 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($f irst_name);
    $last_name = stripslashes($l ast_name);
    $email_address = stripslashes($e mail_address);
    $username = stripslashes($u sername);
    $info = stripslashes($i nfo);

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

    /* if((!$first_nam e) || (!$last_name) || (!$email_addres s) || (!$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_addr ess){
    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_chec k = mysql_query("SE LECT email_address FROM users WHERE
    email_address=' $email_address' ");
    $sql_username_c heck = mysql_query("SE LECT username FROM users WHERE
    username='$user name'");

    $email_check = mysql_num_rows( $sql_email_chec k);
    $username_check = mysql_num_rows( $sql_username_c heck);

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

    function makeRandomPassw ord() {
    $salt = "abcdefghijklmn opqrstuvwxyz123 4567890";
    srand((double)m icrotime()*1000 000);
    $i = 0;
    while ($i <= 7) {
    $num = rand() % 33;
    $tmp = substr($salt, $num, 1);
    $pas = $pass . $tmp;
    $i++
    }
    return $pass;
    }

    $random_passwor d = makeRandomPassw ord();

    $db_password = md5($random_pas sword);

    $info2 = htmlspecialchar s($info);
    $sql = mysql_query("IN SERT 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:
    http://[[domain]]/dbtest/activate.php?id =$userid&amp;co de=$db_password
    Thanks!";
    mail($email_add ress, $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 ());
    ?>


  • Shawn Wilson

    #2
    Re: DB User authentication.

    Allan Hugo wrote:[color=blue]
    >
    > 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="registe r.php">
    > <p>First Name
    > <input name="first_nam e" type="text" id="first_name " value="">
    > <br>
    > Last Name
    > <input type="text" name="last_name " value="">
    > <br>
    > Email Address:
    > <input type="text" name="email_add ress" 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($f irst_name);
    > $last_name = stripslashes($l ast_name);
    > $email_address = stripslashes($e mail_address);
    > $username = stripslashes($u sername);
    > $info = stripslashes($i nfo);
    >
    > echo $first_name . "<br>";
    > echo $last_name . "<br>";
    > echo $email_address . "<br>";
    > echo $username . "<br>";
    > echo $info . "<br>";
    >
    > /* if((!$first_nam e) || (!$last_name) || (!$email_addres s) || (!$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_addr ess){
    > 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_chec k = mysql_query("SE LECT email_address FROM users WHERE
    > email_address=' $email_address' ");
    > $sql_username_c heck = mysql_query("SE LECT username FROM users WHERE
    > username='$user name'");
    >
    > $email_check = mysql_num_rows( $sql_email_chec k);
    > $username_check = mysql_num_rows( $sql_username_c heck);
    >
    > if($email_check > 0 || $username_check > 0) {
    > echo "There were some errors: <br>";
    > if($email_check > 0) {
    > echo "email taken";
    > unset($email_ad dress);
    > }
    > if($username_ch eck > 0) {
    > echo "username taken";
    > unset($username );
    > }
    > include 'index.html';
    > exit();
    > }
    >
    > function makeRandomPassw ord() {
    > $salt = "abcdefghijklmn opqrstuvwxyz123 4567890";
    > srand((double)m icrotime()*1000 000);
    > $i = 0;
    > while ($i <= 7) {
    > $num = rand() % 33;
    > $tmp = substr($salt, $num, 1);
    > $pas = $pass . $tmp;
    > $i++
    > }
    > return $pass;
    > }
    >
    > $random_passwor d = makeRandomPassw ord();
    >
    > $db_password = md5($random_pas sword);
    >
    > $info2 = htmlspecialchar s($info);
    > $sql = mysql_query("IN SERT 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:
    > http://[[domain]]/dbtest/activate.php?id =$userid&amp;co de=$db_password
    > Thanks!";
    > mail($email_add ress, $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 ());
    > ?>[/color]

    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
    shawn@glassgian t.com

    Comment

    • Allan Hugo

      #3
      Re: DB User authentication.


      "Shawn Wilson" <shawn@glassgia nt.com> wrote in message
      news:3FA67685.2 94A0C9D@glassgi ant.com...[color=blue]
      > Allan Hugo wrote:[color=green]
      > >
      > > 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[/color][/color]
      something[color=blue][color=green]
      > > wrong)
      > >
      > > Any help?[/color]
      > <snip>[/color]
      [color=blue]
      > What do you mean by "doesn't work"? Please describe any error messages[/color]
      you're[color=blue]
      > getting, or other indications that it is not working correctly.[/color]

      what do i mean by 'doesn't work'?

      well i get a white page...


      Comment

      • iGadget

        #4
        Re: DB User authentication.

        On Tue, 04 Nov 2003 00:07:26 GMT, Allan Hugo wrote:
        [color=blue]
        >
        > "Shawn Wilson" <shawn@glassgia nt.com> wrote in message
        > news:3FA67685.2 94A0C9D@glassgi ant.com...[color=green]
        >> Allan Hugo wrote:[color=darkred]
        >>>
        >>> 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[/color][/color]
        > something[color=green][color=darkred]
        >>> wrong)
        >>>
        >>> Any help?[/color]
        >> <snip>[/color]
        >[color=green]
        >> What do you mean by "doesn't work"? Please describe any error messages[/color]
        > you're[color=green]
        >> getting, or other indications that it is not working correctly.[/color]
        >
        > what do i mean by 'doesn't work'?
        >
        > well i get a white page...[/color]

        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

        Comment

        • David Robley

          #5
          Re: DB User authentication.

          In article <9Tppb.176838$b o1.114413@news-server.bigpond. net.au>,
          someone@microso ft.com says...[color=blue]
          > 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.[/color]

          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...
          [color=blue]
          > 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:[/color]
          <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?

          Comment

          Working...