1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

is it really hard to setup a php user registration site

Discussion in 'PHP' started by phpwreker, Dec 12, 2011.

  1. #1
    :confused:
     
    phpwreker, Dec 12, 2011 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    How long was that piece of string?
     
    mfscripts, Dec 12, 2011 IP
  3. serena85

    serena85 Peon

    Messages:
    892
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I really do not understand what you are trying to ask or to say to us....please rephrase.
     
    serena85, Dec 12, 2011 IP
  4. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #4
    serena85, who me?
     
    mfscripts, Dec 12, 2011 IP
  5. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    this is from the dummies book

    create new account ...

    <?php
    /* File: login_form.inc
    * Desc: Displays login page. Page displays two forms:
    * one form for entering an existing login name
    * and password and another form for the
    * information needed to apply for a new account.
    */
    include(“function12.inc”); 
    ?>
    <html>
    <head>
    <title>Members Only Login</title>
    <style type=”text/css”><!--
    .bold_right {font-weight: bold; text-align: right;}
    .gray_banner { font-weight: bold; color: white;
    
    background-color: gray;
    text-align: center; font-size: 3em;}
    .bold_large {font-size: 1.1em; font-weight: bold;}
    --></style>
    </head>
    <body style=”margin: 0”>
    <table border=”0” cellpadding=”5” cellspacing=”0”>
    <tr><td colspan=”3” class=”gray_banner”>
    Members Only Section</td></tr>
    <tr><td width=”33%” valign=”top” class=”bold_large”>
    Are you a member?
    <!-- form for Member login -->
    <form action=”Login.php” method=”POST”>
    <p><table border=”0”>
    <?php #30
    if (isset($message))
    {
    echo “<tr><td style=’color: red’
    colspan=’2’ >$message <br /></td></tr>”;
    }
    ?>
    <tr><td class=”bold_right”>Username</td>
    <td><input type=”text” name=”fusername”
    size=”20” maxsize=”20”></td></tr>
    <tr><td class=”bold_right”>Password</td>
    <td><input type=”password” name=”fpassword”
    size=”20” maxsize=”20”></td></tr>
    <input type=”hidden” name=”do”
    value=”login”>
    <tr><td style=”text-align: center” colspan=”2”>
    <br /><input type=”submit” name=”log”
    value=”Enter”></td></tr>
    </table>
    </form>
    </td>
    <td style=”width: 1; background-color: gray”></td>
    <td style=”width: 67%”><p>
    <span class=”bold_large”>Not a member yet?</span>
    Get discounts, a newsletter, advance notice
    of new pets, much more. Fill in the information
    below and join. It’s easy and free!</p>
    <!-- form for new member to fill in -->
    <form action=”Login.php” method=”POST”>
    <table border=”0” width=”100%”>
    <?php #60
    if (isset($message_new))
    {
    echo “<tr><td style=’color: red;
    font-weight: bold’ colspan=’2’>
    <p>$message_new</p></td></tr>”;
    }
    ?>
    
    <tr><td class=”bold_right”>Member ID</td>
    <td><input type=”text” name=”loginName”
    value=”<?php echo @$loginName ?>”
    size=”20” maxlength=”20”></td></tr>
    <tr><td class=”bold_right”>Password</td>
    <td><input type=”password” name=”password”
    value=”<?php echo @$password ?>”
    size=”10” maxlength=”8”></td></tr>
    <tr><td class=”bold_right”>First Name</td>
    <td><input type=”text” name=”firstName”
    value=”<?php echo @$firstName ?>”
    size=”40” maxlength=”40”></td></tr>
    <tr><td class=”bold_right”>Last Name</td>
    <td><input type=”text” name=”lastName”
    value=”<?php echo @$lastName ?>”
    size=”40” maxlength=”40”></td></tr>
    <tr><td class=”bold_right”>Street</td>
    <td><input type=”text” name=”street”
    value=”<?php echo @$street ?>”
    size=”55” maxlength=”50”></td></tr>
    <tr><td class=”bold_right”>City</td>
    <td><input type=”text” name=”city”
    value=”<?php echo @$city ?>”
    size=”40” maxlength=”40”></td></tr>
    <tr><td class=”bold_right”>State</td>
    <td><select name=”state”>
    <?php
    $stateName=getStateName(); 
    $stateCode=getStateCode(); 
    for ($n=1;$n<=50;$n++)
    {
    $state=$stateName[$n];
    $scode=$stateCode[$n];
    echo “<option value=’$scode’”;
    if ($scode== “AL”)
    echo “ selected”;
    echo “>$state\n”;
    }
    ?>
    </select>
    &nbsp;&nbsp;&nbsp;&nbsp;<b>Zip</b>
    <input type=”text” name=”zip”
    value=”<?php echo @$zip ?>”
    size=”10” maxsize=”10”>
    </td></tr>
    <tr><td class=”bold_right”>Phone</td>
    <td><input type=”text” name=”phone”
    350 Part IV: Applications
    value=”<?php echo @$phone ?>”
    size=”15” maxlength=”20”>
    &nbsp;&nbsp;&nbsp;<b>Fax</b>
    <input type=”text” name=”fax”
    value=”<?php echo @$fax ?>”
    size=”15” maxlength=”20”></td></tr>
    <tr><td class=”bold_right”>Email Address</td>
    <td><input type=”text” name=”email”
    value=”<?php echo @$email ?>”
    size=”55” maxlength=”67”></td></tr>
    <input type=”hidden” name=”do” value=”new”>
    <tr><td>&nbsp;</td>
    <td style=”text-align: center”>
    <input type=”submit”
    value=”Become a Member”></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    <tr><td colspan=”3”
    style=”background-color: gray”>&nbsp;</td></tr>
    </table>
    <div style=”text-align: center; font-size: .8em”>
    All comments and suggestions are appreciated. Please
    send comments to
    <a href=”mailto:webmaster@petstore.com”>
    [EMAIL="webmaster@petstore.com"]webmaster@petstore.com[/EMAIL]</a></div>
    </body></html>                      
    Code (markup):
    ...

    login form




    <?php
    /* Program: Login.php
    * Desc: Login program for the Members Only section of
    * the pet store. It provides two options:
    * (1) login using an existing Login Name and
    * (2) enter a new login name. Login Names and
    * passwords are stored in a MySQL database.
    */
    session_start(); 
    include(“dogs.inc”); 
    switch (@$_POST[‘do’]) 
    {
    case “login”: 
    $cxn = mysqli_connect($host, $user,$passwd,$dbname)
    or die (“Couldn’t connect to server.”); 
    $sql = “SELECT loginName FROM Member
    WHERE loginName=’$_POST[fusername]’”; 
    $result = mysqli_query($cxn,$sql)
    or die(“Couldn’t execute query.”); 
    $num = mysqli_num_rows($result); 
    if ($num > 0) // login name was found 
    {
    $sql = “SELECT loginName FROM Member
    WHERE loginName=’$_POST[fusername]’
    AND password=md5(‘$_POST[fpassword]’)”;
    $result2 = mysqli_query($cxn,$sql)
    or die(“Couldn’t execute query 2.”);
    $num2 = mysqli_num_rows($result2);
    if ($num2 > 0) // password is correct 
    {
    $_SESSION[‘auth’]=”yes”; 
    $logname=$_POST[‘fusername’];
    $_SESSION[‘logname’] = $logname; 
    $today = date(“Y-m-d h:i:s”); 
    $sql = “INSERT INTO Login (loginName,loginTime)
    VALUES (‘$logname’,’$today’)”;
    $result = mysqli_query($cxn,$sql)
    or die(“Can’t execute insert query.”);
    header(“Location: Member_page.php”); 
    }
    
    else // password is not correct 
    {
    $message=”The Login Name, ‘$_POST[fusername]’
    exists, but you have not entered the
    correct password! Please try again.<br />”;
    include(“login_form.inc”); 
    }
    } 
    elseif ($num == 0) // login name not found 
    {
    $message = “The Login Name you entered does not
    exist! Please try again.<br>”;
    include(“login_form.inc”);
    }
    break; 
    case “new”:
    /* Check for blanks */ 
    foreach($_POST as $field => $value) 
    {
    if ($field != “fax”) 
    {
    if ($value == “”) 
    {
    $blanks[] = $field;
    }
    }
    }
    if(isset($blanks)) 
    {
    $message_new = “The following fields are blank.
    Please enter the required information: “;
    foreach($blanks as $value)
    {
    $message_new .= “$value, “;
    }
    extract($_POST);
    include(“login_form.inc”);
    exit();
    }
    /* Validate data */
    foreach($_POST as $field => $value) 
    {
    if(!empty($value)) 
    {
    if(eregi(“name”,$field) and
    !eregi(“login”,$field))
    {
    if (!ereg(“^[A-Za-z’ -]{1,50}$”,$value))
    {
    $errors[]=”$value is not a valid name.”;
    
    
    }
    }
    if(eregi(“street”,$field) or
    eregi(“addr”,$field) or eregi(“city”,$field))
    {
    if(!ereg(“^[A-Za-z0-9.,’ -]{1,50}$”,$value))
    {
    $errors[] = “$value is not a valid
    address or city.”;
    }
    }
    if(eregi(“state”,$field))
    {
    if(!ereg(“[A-Za-z]{2}”,$value))
    {
    $errors[]=”$value is not a valid state.”;
    }
    }
    if(eregi(“email”,$field))
    {
    if(!ereg(“^.+@.+\\..+$”,$value))
    {
    $errors[] = “$value is not a valid
    email address.”;
    }
    }
    if(eregi(“zip”,$field))
    {
    if(!ereg(“^[0-9]{5,5}(\-[0-9]{4,4})?$”,
    $value))
    {
    $errors[]=”$value is not a valid
    zipcode.”;
    }
    }
    if(eregi(“phone”,$field)
    or eregi(“fax”,$field))
    {
    if(!ereg(“^[0-9)(xX -]{7,20}$”,$value))
    {
    $errors[] = “$value is not a valid
    phone number. “;
    }
    }
    } // end if empty 
    } // end foreach
    if(@is_array($errors)) 
    {
    $message_new = “”;
    foreach($errors as $value)
    342 Part IV: Applications
    {
    $message_new .= $value.” Please try
    again<br />”;
    }
    extract($_POST);
    include(“login_form.inc”);
    exit();
    }
    /* clean data */
    $cxn = mysqli_connect($host,$user,$passwd,$dbname);
    foreach($_POST as $field => $value) 
    {
    if($field != “Button” and $field != “do”)
    {
    if($field == “password”)
    {
    $password = strip_tags(trim($value));
    }
    else
    {
    $fields[]=$field;
    $value = strip_tags(trim($value));
    $values[] =
    mysqli_real_escape_string($cxn,$value);
    $$field = $value;
    }
    }
    }
    /* check whether user name already exists */
    $sql = “SELECT loginName FROM Member
    WHERE loginName = ‘$loginName’”; 
    $result = mysqli_query($cxn,$sql)
    or die(“Couldn’t execute select query.”);
    $num = mysqli_num_rows($result); 
    if ($num > 0) 
    {
    $message_new = “$loginName already used.
    Select another User Name.”;
    include(“login_form.inc”);
    exit();
    }
    /* Add new member to database */
    else 
    {
    $today = date(“Y-m-d”);
    $fields_str = implode(“,”,$fields);
    $values_str = implode(‘“,”’,$values);
    $fields_str .=”,createDate”;
    
    $values_str .=’”’.”,”.’”’.$today;
    $fields_str .=”,password”;
    $values_str .= ‘“‘.”,”.”md5”.”(‘“.$password.”’)”;
    $sql = “INSERT INTO Member “;
    $sql .= “(“.$fields_str.”)”;
    $sql .= “ VALUES “;
    $sql .= “(“.’”’.$values_str.”)”;
    $result = mysqli_query($cxn,$sql)
    or die(“Couldn’t execute insert query.”);
    $_SESSION[‘auth’]=”yes”; 
    $_SESSION[‘logname’] = $loginName;
    /* send email to new member */ 
    $emess = “A new Member Account has been set up. “;
    $emess.= “Your new Member ID and password are: “;
    $emess.= “\n\n\t$loginName\n\t$password\n\n”;
    $emess.=”We appreciate your interest in Pet”;
    $emess.= “ Store at PetStore.com. \n\n”;
    $emess.= “If you have any questions or problems,”;
    $emess.= “ email [EMAIL="webmaster@petstore.com"]webmaster@petstore.com[/EMAIL]”;
    $ehead=”From: [EMAIL="member-desk@petstore.com"]member-desk@petstore.com[/EMAIL]\r\n”; 
    $subj = “Your new Member Account from Pet Store”;
    $mailsnd=mail(“$email”,”$subj”,”$emess”,”$ehead”);
    header(“Location: New_member.php”); #218
    }
    break; 
    default: 
    include(“login_form.inc”);
    }
    ?>
    Code (markup):

    somebody please help ..
     
    phpwreker, Dec 12, 2011 IP
  6. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #6
    What errors are you getting?
     
    mfscripts, Dec 12, 2011 IP
  7. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    i need someplace to test this scripts..

    i dont really know how to set these scripts up and running
     
    phpwreker, Dec 12, 2011 IP
  8. Karl-

    Karl- Greenhorn

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #8
    Get WampServer and install it on your PC, you can test them there.
     
    Karl-, Dec 12, 2011 IP
  9. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #9
    Hahah, almost got me, nice trolling.
     
    Kaizoku, Dec 13, 2011 IP
  10. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #10
    ok ..

    one really stupid question ..

    which one is going to be my index.html home page .. or index.php homepage ?
     
    phpwreker, Dec 17, 2011 IP
  11. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #11
    can someone tell me a nice irc help channel for php?
     
    phpwreker, Dec 22, 2011 IP
  12. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #12
    thanks.. i think i started this a month ago.. did not had any clue like where to start etc..after reading a few books i have decided to start here..

    now i have a wamp server ..

    i have not configured a user and a password for mysql..do i really need that ?

    i have created a database (database name ) and table in it .. with phpmyadmin

    now i cannot make an html form insert data into the database ..

    how do i do that?
     
    Last edited: Dec 25, 2011
    phpwreker, Dec 25, 2011 IP