Welcome Guest, Not a member yet? Register   Sign In
help me in my function codes
#1

[eluser]adamsonit[/eluser]
Undefined index: login in C:\wamp\www\Copy of mathdept\dbconnect\dbconnect.php on line 59
Undefined variable: error in C:\wamp\www\Copy of mathdept\dbconnect\dbconnect.php on line 106

Code:
<?php
mysql_connect('localhost','root',"") or die('cannot connect');
    mysql_select_db('mathematics')or die('cannot connect to db');

        
function loginForm()
{
echo '    
    <div id="container2">
        <div id="nav-right">
        <div id="sideright-top"><p class="class2">Log In</p></div>
        <div id="sideright-bg">
        &lt;form id="form1" name="form1" method="post" action="verify.php?invalid=&lt;?php echo "Invalid Username or Password!"; ?&gt;"&gt;
  <table width="232" border="0">
    <tr>
      <td width="72"><p>Username</p></td>
      <td width="150">&lt;input name="username" type="text" id="username" /&gt;&lt;/td>
    </tr>
    <tr>
      <td><p >Password</p></td>
      <td>&lt;input name="password" type="text" id="password" /&gt;&lt;/td>
    </tr>
    <tr>
    <td>
    </td>
    </tr>
    <tr>
      <td><p  >Register</p></td>
      <td>&lt;input type="submit" name="Submit" value="Login" /&gt;&lt;/td>
    </tr>
  </table>
  
  
  
&lt;/form&gt;
</div>
<div id="sideright-buttom"></div>';

}

function userInfo($employeeid)
        {
            $query = "select username' from login where employeeid = '$employeeid'";
            $getName = mysql_query($query);
            $rowName = mysql_fetch_array($getName);
            $name = $rowName['username'];
            echo '
            <div id="container2">
            <div id="nav-right">
            <div id="sideright-top"><p class="class2">Welcome, '.$name. '</p></div>
            <div id="sideright-bg">
            </div>
            <div id="sideright-buttom"></div>';
        }
        
        
        function login_lib()
        {
            if($_POST['login'])
            {
                $username=$_POST['username'];
                $password=$_POST['password'];
                
                //check user if existing
                $query = "select *
                          from login
                          where
                            username = '$username'
                            and password = '$password'
                            and type !=1 ";
                $checkUser = mysql_query($query);
                
                if(mysql_num_rows($checkUser)!=1)
                {
                    $error = true;
                    $errMsg ='Error trying to validate user!';
                }
                elseif(mysql_num_rows($checkUser)==1)
                {
                    $row = mysql_fetch_array($checkUser);
                    $userLevel = $row['type'];
                    $employeeid=$row['employeeid'];
                    if($userLevel ==2)
                    {
                        $_SESSION['loginSuccess'] = 'success';
                        $_SESSION['userLevel'] =2;
                        $_SESSION['employeeid'] = $employeeid;
                        header("location:index.php");
                    }
                    else
                    {
                        header("location:/faculty/index.php");
                        $_SESSION['loginSuccess'] = 'success';
                        $_SESSION['userLevel'] =3;
                        $_SESSION['userid'] = $employeeid;
                        header("location:index.php");
                    }
                }
                else
                {
                    header("location:/mathdept");
                }
                
            }
            
            return $error;
        }
    ?&gt;
#2

[eluser]adamsonit[/eluser]
and when i login Cannot redeclare loginform() (previously declared in C:\wamp\www\Copy of mathdept\dbconnect\dbconnect.php:37) in C:\wamp\www\Copy of mathdept\dbconnect\dbconnect.php on line 39

index.php
Code:
&lt;?php
session_start(); ?&gt;

&lt;?php
// Connect to the database
     $cnx = mysql_connect("localhost", "root", "");
         if (!$cnx) {
         die("Unable to connect to database!");
         }
          
// Select your database
  mysql_select_db("mathematics", $cnx);
  
// Get data from the database
  $query = mysql_query("SELECT data FROM homepage WHERE id = 1");
  $data = mysql_fetch_array($query);
  ?&gt;

&lt;?php
include("dbconnect/dbconnect.php");
$error=login_lib();
include("includes/header.php");
?&gt;
    <div id="buttons"><ul id="navigation-1">
   <li><a href="index.php" title="Homepage">Home</a></li>
   <li><a href="aboutmath.php" title="About Math">About Math</a>
      <ul class="navigation-2">
      <li><a href="news.php" title="News and Events">News and Events</a></li>
      <li><a href="course_offered.php" title="BS Math">Course Offered</a></li>
      <li><a href="faculty.php" title="Faculty Members">Faculty Members</a></li>
      <li><a href="alumni.php" title="Alumni">Alumni</a></li>
      <li><a href="subjects.php" title="Subjects">Subjects</a></li>

      </ul>
   </li>
   <li><a href="#" title="Forum">Forum</a></li>
   <li><a href="downloads.php" title="Downloads">Downloads</a>
   </li>
   <li><a href="gallery.php" title="Gallery">Gallery</a>
      <ul class="navigation-2">
         <li><a href="#" title="Photos">Photos</a></li>
         <li><a href="#" title="Videos">Videos</a></li>
      </ul>
   </li>
   <li><a href="sitemap.php" title="Sitemap">Sitemap</a>
</ul></div>
&lt;?php if($error==true){
            error();
        }
    ?&gt;
        &lt;?php if(isset($_SESSION['loginSuccess']))
              {
                userInfo($_SESSION['employeeid']);
            }
            else
            {
                loginForm();
            }
      ?&gt;
&lt;?php
include("includes/announcements.php"); ?&gt;
<div id="sideleft-top"><p class="class1">Welcome to Mathematics Department</p></div>
<div id="sideleft-bg">
&lt;?php echo $data['data']; ?&gt;
</div>
<div id="sideleft-buttom"></div>
</div>
&lt;?php
include("includes/footer.php");
?&gt;
#3

[eluser]pistolPete[/eluser]
I don't see any relation to CodeIgniter at all!




Theme © iAndrew 2016 - Forum software by © MyBB