Results 1 to 2 of 2

Thread: Login Srcpt help

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Exclamation Login Srcpt help

    Hi guys working on simple login script i have this for register
    PHP Code:
    <form id="loginForm" name="loginForm" method="post" action="register-exec.php">
      <
    table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
        <
    tr>
          <
    th>First Name </th>
          <
    td><input name="fname" type="text" class="textfield" id="fname" /></td>
        </
    tr>
        <
    tr>
          <
    th>Last Name </th>
          <
    td><input name="lname" type="text" class="textfield" id="lname" /></td>
        </
    tr>
        <
    tr>
          <
    th width="124">Login</th>
          <
    td width="168"><input name="login" type="text" class="textfield" id="login" /></td>
        </
    tr>
        <
    tr>
          <
    th>Password</th>
          <
    td><input name="password" type="password" class="textfield" id="password" /></td>
        </
    tr>
        <
    tr>
          <
    th>Confirm Password </th>
          <
    td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td>
        </
    tr>
        <
    tr>
          <
    th>E-Mail Address </th>
          <
    td><input name="email" type="text" class="textfield" id="email" /></td>
        </
    tr>
        <
    tr>
          <
    td>&nbsp;</td>
          <
    td><input type="submit" name="Submit" value="Register" /></td>
        </
    tr>
      </
    table>
    </
    form
    AND THIS

    PHP Code:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Include database connection details
        
    require_once('config.php');
        
        
    //Array to store validation errors
        
    $errmsg_arr = array();
        
        
    //Validation error flag
        
    $errflag false;
        
        
    //Connect to mysql server
        
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
        
    //Select database
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    "Unable to select database");
        }
        
        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
        
        
    //Sanitize the POST values
        
    $fname clean($_POST['fname']);
        
    $lname clean($_POST['lname']);
        
    $login clean($_POST['login']);
        
    $password clean($_POST['password']);
        
    $cpassword clean($_POST['cpassword']);
        
    $email clean($_POST['email']);
        
        
    //Input Validations
        
    if($fname == '') {
            
    $errmsg_arr[] = 'First name missing';
            
    $errflag true;
        }
        if(
    $lname == '') {
            
    $errmsg_arr[] = 'Last name missing';
            
    $errflag true;
        }
        if(
    $login == '') {
            
    $errmsg_arr[] = 'Login ID missing';
            
    $errflag true;
        }
        if(
    $password == '') {
            
    $errmsg_arr[] = 'Password missing';
            
    $errflag true;
        }
        if(
    $cpassword == '') {
            
    $errmsg_arr[] = 'Confirm password missing';
            
    $errflag true;
        }
        if( 
    strcmp($password$cpassword) != ) {
            
    $errmsg_arr[] = 'Passwords do not match';
            
    $errflag true;
        }
        if(
    $email == '') {
            
    $errmsg_arr[] = 'E-Mail missing';
            
    $errflag true;
        }
        
    //Check for duplicate login ID
        
    if($login != '') {
            
    $qry "SELECT * FROM members WHERE login='$login'";
            
    $result mysql_query($qry);
            if(
    $result) {
                if(
    mysql_num_rows($result) > 0) {
                    
    $errmsg_arr[] = 'Login ID already in use';
                    
    $errflag true;
                }
                @
    mysql_free_result($result);
            }
            else {
                die(
    "Query failed");
            }
        }
        
        
    //If there are input validations, redirect back to the registration form
        
    if($errflag) {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            
    session_write_close();
            
    header("location: register-form.php");
            exit();
        }

        
    //Create INSERT query
        
    $qry "INSERT INTO members(firstname, lastname, login, passwd, email) VALUES('$fname','$lname','$login','".md5($_POST['password'])."','$email')";
        
    $result = @mysql_query($qry);
        
        
    //Check whether the query was successful or not
        
    if($result) {
            
    header("location: index.php");
            exit();
        }else {
            die(
    "Query failed");
        }
    ?>
    But how would i make a edit profile?
    Last edited by TwitterRooms; 01-14-2012 at 01:07 PM.

  2. #2
    Join Date
    Jan 2012
    Location
    India
    Posts
    45
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    just edit your register page

    PHP Code:
    <?php
    $cnn 
    mysql_connect("hostname","dbuser","dbpass");
    $db mysql_select_db("db");
    // get id where records are showing
    $id $_GET['id'];
    $sql "SELECT * FROM tablename WHERE id='$id'";
    $result mysql_query($sql);
    $row mysql_fetch_row($result);

    // or you can use your config file

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form id="updateForm" name="updateForm" method="post" action="update.php">
    <input type="hidden"  name="id" value="<?php echo $id?>">
      <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr>
          <th>First Name </th>
          <td><input name="fname" type="text" class="textfield" value="<?php echo $row[1]; ?>" id="fname" /></td>
        </tr>
        <tr>
          <th>Last Name </th>
          <td><input name="lname" type="text" class="textfield" value="<?php echo $row[2]; ?>" id="lname" /></td>
        </tr>
        <tr>
          <th width="124">Login</th>
          <td width="168"><input name="login" type="text" class="textfield" value="<?php echo $row[3]; ?>" id="login" /></td>
        </tr>
        <tr>
          <th>Password</th>
          <td><input name="password" type="password" class="textfield" value="<?php echo $row[4]; ?>" id="password" /></td>
        </tr>
        <tr>
          <th>Confirm Password </th>
          <td><input name="cpassword" type="password" class="textfield" value="<?php echo $row[5]; ?>" id="cpassword" /></td>
        </tr>
        <tr>
          <th>E-Mail Address </th>
          <td><input name="email" type="text" class="textfield" value="<?php echo $row[6]; ?>" id="email" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="Submit" value="Update" /></td>
        </tr>
      </table>
    </form>  
    </body>
    </html>
    Last edited by ankush; 01-19-2012 at 07:15 AM.

  3. The Following User Says Thank You to ankush For This Useful Post:

    TwitterRooms (01-19-2012)

Bookmarks

Posting Permissions

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