Jump to content

zzz

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Posts posted by zzz

  1. im running win98 /PHP4.0.5 / MYsqlWIN32

    i am trying to setup a login system for my project at school...

    my Table structure for table `registrationform`

     

     

     

    CREATE TABLE registrationform (
    Member_ID int(10) NOT NULLdefault '0',
    Member_Pass varchar(10) NOT NULL default '0',
    Member_RePass varchar(10) NOT NULL default '0',
    Member_Name varchar(100) NOT NULL ,
    Member_IC varchar(20) NOT NULL,
    Member_Phone varchar(20) NULL,
    Member_Email varchar(50) NOT NULL,
    Member_Sex varchar(6) NOT NULL,
    Member_Age int(3) NOT NULL,
    Member_Status varchar(20) NOT NULL,
    Member_Occ varchar(50) NOT NULL,
    Member_Add text NOT NULL,
    Member_State varchar(30) NULL,
    Member_AddDetail text NULL
    
    )

    i have 4 related php.files here to do with the login system -memberlogin.php / login.php / connect_db.php / and common_lib.php

    1)login.php

    [PHP]
    <?php 
    $str = "<font class=\"success\"> Member Area</font>";
    if($login == "error") {
     $str = "<font  face=verdana color=red><b>LOGIN ERROR!: </font><font color=black>Wrong Username Or Password</b></font>";
    }
    elseif($login == "blocked") {
     $str = "<font  face=verdana color=red><b>YOUR ACCESS HAS BEEN BLOCKED!</b></font>";
    }
    elseif($login == "session") {
     $str = "<font  face=verdana color=red><b>SESSION ERROR!: <font color=black>User Already Connected. Please Logout First</font></b></font></center>";
    }
    elseif($login == "") {
    }
    elseif($login == "logout") 
    {
     $str = "<font class=\"success\">User <font color=blue>$User_Login</font> Logged Out</font>";
       }
    else
       {
     $str = "<font  face=verdana color=red><b>LOGIN ERROR!: </font><font color=black>Wrong Username Or Password</b></font>";
    }
    
    include("connect_db.php");
    include("common_lib.php");
    
    ?>	
    <html>
    <head>
    <title>Login Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="mainstyle.css" rel="stylesheet" type="text/css">
    <script>
    function focus_login()
    {
    document.login_form.User_Login.focus();
    } 
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" onLoad="focus_login();">
    <br><br><font class="maintitle"><center>Welcome to WebMedic HealthNet</center></font><br>
    <center>
    <table width="40%" border="0" cellspacing="0" cellpadding="0">
     <tr><td colspan="center" border=0 bordercolor="#FFFFFF" align="left"><?php echo " $str "; ?></td></tr>
    </table>
    </center>
    <center>
    <table width="40%" border="0" cellspacing="0" cellpadding="0" style="border: #003366; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; font-size: 10pt;">  
     <tr>
         <td colspan=2 class="title" valign="center"> WebMedic HealthNet Member Login</td>
     </tr>
     <form name="login_form" method="post" action="memberlogin.php">
     <tr>
       <td colspan=2 class=content> </td>
     </tr>
     <tr>
       <td width="35%" align=right class=details> 
    User Name: 
    </td>
    <td class=content width="65%"> 
             <input class="textbox" type="text" name="User_Login">
       </td>
     </tr>
      <tr>
       <td colspan=2 class=content> </td>
     </tr>
     <tr>
     <td width="35%" align=right class=details>
    Password: 
    </td>
    <td class=content width="65%">    
              <input class="textbox" type="password" name="User_Password">
       </td>
     </tr>
      <tr>
       <td colspan=2 class=content> </td>
     </tr>
     <tr class="content">
       <td colspan=2 align="center">
    
       <input class="button" name="signin" type="submit" value="Sign In">
       <input class="button" name="close" type="submit" value="Close" onClick="window.close();">    
       
       </td>
     </tr>
     <tr class="content"><td align=left><font class="success">New User? <a href="memreg.php">Sign Up</a></font></td>
           
           <td align=right><font class="success"> </font></td>
         </tr>
     <tr class="content">
     	<td height="12" colspan=2>
    <center>
             </center>
     	</td>
     </tr>
     </form>
    </table>
    
    </center>
    
    </body>
    </html>
    <?php
    if($status == "usersuccess") {
    echo "<script>alert('You successfully signed up!</script>";
    }
    
    ?>
    [/PHP]
    

    2)memberlogin.php

    [php]
    <?php 
    session_start();
    //connect to the DB
    include ("connect_db.php");
    include ("common_lib.php");
    
    
    //set up the query
    $User_Login = $Member_ID;
    $User_Password= md5($Member_Pass);
    $query = "SELECT * FROM registrationform WHERE User_Login='".$Member_ID."' AND User_Password='".$Member_Pass."'";
    
    
     	
    //run the query and get the number of affected rows
    $result = mysql_query($query, $connection) or die('error making query');
                     $myrow = mysql_fetch_array($result); 
    $affected_rows = mysql_num_rows($result);
    
    if($affected_rows <> 0) {
                  $_SESSION['Session_Member_ID'] = $User_Login; //register user in session
                  $_SESSION['Session_Member_Pass'] = $myrow["User_Password"];
     
       }
    
    else {
     $relative_url = "login.php?login=error";
     redirect($relative_url);     
    }
    
    ?>
    [/php]
    

    3)common_lib.php

    [php]
    <?php
    function redirect($url)
    {
     $relative_url = $url;
     header("Location: http://".$_SERVER['HTTP_HOST']
                         .dirname($_SERVER['PHP_SELF'])
                         ."/".$relative_url);
     exit; 
    }
    
    function display_time_date() {
    //get login time/date
    $today = getdate(); 
    $month = $today['month']; 
    $day = $today['mday']; 
    $year = $today['year']; 
    $hours = $today['hours'];
    $minutes = $today['minutes'];
    $seconds = $today['seconds'];
    
    if($seconds < 10)
    {
    $seconds = "0".$seconds;
    }
    if($minutes < 10)
    {
    $minutes = "0".$minutes;
    }
    
    
    $txt = "AM ";
    if($hours >= 12) 
    { $hours = $hours - 12;
    $txt = "PM ";
    }
    
    if($hours < 10)
    {
    $hours = "0".$hours;
    }
    
    $Member_ID = strtolower($_SESSION['Session_Member_ID']);
    $query = "SELECT * FROM registrationform WHERE Member_ID = '$Member_ID'";
    $result = mysql_query($query) or die('error making query');
    $myrow = mysql_fetch_array($result); 
    $Member_Name = $myrow[Member_Name];
    
    echo "<font class=\"success\">Member logged in : ".$Member_Name; 
    echo " | ";
    echo "Connected on $day $month, $year at $hours:$minutes:$seconds $txt </font>";
    
    }
    
    function Format_Date($unformatted_date)
    {
     $year = substr($unformatted_date,0,4);
     $month = substr($unformatted_date,5,-3);
     $day = substr($unformatted_date,8,9);
     
     $formatted_date = $day ."/" . $month ."/" . $year;
     return $formatted_date;
    
    }
    ?>
    [/php]
    

    4)connect_db.php

     

    [php]
    <?php
     $connection = mysql_connect("localhost", "z", "z") or die(mysql_error());
     mysql_select_db("registration", $connection) or die(mysql_error());
    ?>
    
    [/php]
    

    when i run http://localhost/login.php the login page is ok, but when i try to login(no matter with correct username/password or incorrect usernae/password) the error message "error making query" appear..it there a problem in my codes?connection to databse problems??or...??i'm so screw up with it ..i don't know what to do to fix it!!please help me..anyone:((???Thanks in advanced..

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.