Results 1 to 5 of 5

Thread: Login Script

  1. #1
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Login Script

    Hey guys,

    I need some help, Im trying to make a members section, and so i have a username and password page, which passes to a login.php script..

    username and password are passed to this page
    PHP Code:
    <?php
    include "connection.php";

    // Connect to server and select databse.
    if (!$con)
      {
      die(
    'Could not connect: ' mysql_error() );
      }
      
    mysql_select_db($db$con);

    // username and password sent from signup form 
    $username=$_POST['username']; 
    $username=$_POST['password']; 

    $sql="SELECT * FROM our_info WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){
    // Register $myusername, $mypassword and redirect to file "failed.html"
    session_register("username");
    session_register("password"); 
    header("location:../main.php");
    }
    else {
    header("location:../failed.html");
    }
    ?>
    but for some reason it keeps sending me to failed.php, even though the username and password are correct...

    any thoughts?

  2. #2
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oh....

    how stupid am i??

    PHP Code:
    // username and password sent from signup form  
    $username=$_POST['username'];  
    $username=$_POST['password']; 
    ok, so, thats now working

  3. #3
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok,

    this is the script
    PHP Code:
    <?php
    include "connection.php";

    // Connect to server and select databse.
    if (!$con)
      {
      die(
    'Could not connect: ' mysql_error() );
      }
      
    mysql_select_db($db$con);

    // username and password sent from signup form 
    $user=$_POST['username']; 
    $pass=$_POST['password']; 

    $sql="SELECT * FROM our_info WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){
    // Register $myusername, $mypassword and redirect to file "failed.html"
    session_register("user");
    session_register("pass"); 
    header("location:../main.php");
    }
    else {
    header("location:../failed.html");
    }
    ?>
    that worked, however, on another script, it stopped working..

    PHP Code:
    <?PHP
    //Get the data to update

    $contact $_POST['contact'];
    $business $_POST['business'];
    $add1 $_POST['add1']; 
    $add2 $_POST['add2']; 
    $town $_POST['town']; 
    $county $_POST['county']; 
    $postcode $_POST['postcode']; 
    $country $_POST['country']; 
    $tel $_POST['tel']; 
    $fax $_POST['fax']; 
    $email $_POST['email']; 
    $web $_POST['web']; 
    $view $_POST['view']; 

    // Make Connection
    include 'connection.php';
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error() );
      }
      
    mysql_select_db($db$con);

    //Run the update query
     
    $sql "UPDATE our_info SET contact = '$contact' , business = '$business' , add1 = '$add1' , add2 = '$add2' , town = '$town' , county = '$county' , postcode = '$postcode' , country = '$country' , tel = '$tel' , fax = '$fax' , email = '$email' , web = '$web' , view = '$view' WHERE username = '$user'";
     
      
    mysql_query$sql $con ) or die( "<strong>Query Error</strong>: " mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); 

    echo 
    $user ;
    //Close the connection
      
    mysql_close($con);
      
    ?>
    <META HTTP-EQUIV="Refresh"    CONTENT="0; URL=../yourdetails.php">
    the echo works fine but it doesnt update the database..?

    any thoughts?

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    What error does it give?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    I think i can make a login script but i dont know what you need and etc.
    i have the script for log in
    Code:
    <html>
    <head>
    <script>
    function show(){
    document.resetpass.style.display="block";
    }
    </script>
    <title>4 charx</title>
    </head>
    
    <body>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <form method="POST" action="log_con.php">
    	<div align="center">
    	<table border="0" width="854" id="table1">
    		<tr>
    			<td width="100&#37;" colspan="2" align=center><b>&nbsp;&nbsp;&nbsp; Admin Panel Entry</b></td>
    		</tr>
    		<tr>
    			<td width="44%" align=right>Username:</td>
    			<td width="55%">
    			<input name="username" size="20" style="font-family: Tahoma; font-size: 8pt; color: #FFFFFF; background-color:#838FB9"></td>
    		</tr>
    		<tr>
    			<td width="44%" align=right>Password:</td>
    			<td width="55%">
    			<input type="password" name="password" size="20" style="font-family: Tahoma; font-size: 8pt; color: #FFFFFF; background-color:#838FB9"></td>
    		</tr>
    		<tr>
    			<td width="44%">&nbsp;</td>
    			<td width="55%">
    			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    			<input type="submit" value="Enter"></td>
    		</tr>
    	</table>
    	</div>
    </form>
    <center>
    <a href="javascript:show()"><font color="#FF0000">Şifrəmi unutdum</font></a>
    		<form  action="sendpass.php" method="post" name="resetpass" style='display:none'><br>
    			Qeydiyyatdan ke&#231;ən e-mail-i daxil edin:<input type=text name="email" value="" size=20>
    			<input type=submit value="Send password">
    		</form>
    	
    </body>
    
    </html>
    this is a log in page

    and this is the log_conf script

    Code:
    <?
    session_start();
    $username=$_POST["username"];
    $password=md5($_POST["password"]);
    include_once("../include/connect.inc"); connect(1,2);
    $info=mysql_query("select * from login where username='$username' and password='$password'");
    $count=mysql_num_rows($info);
    if ($count>0){
    	$log=mysql_fetch_array($info);
    	session_register("username","password");
    	$login=$log["username"];
    	$password=$log["password"];
    	Header("Location: admin.php");
    }
    else{
    	Header("Location: login.php");
    }
    ?>
    i dont think that will work you need to change all thing but i can send you all files to your e-mail if you want

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
  •