Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem with using SELECT

    Hi guys. i have this problem that i cant seem to fix. the select * from isnt showing anything.. here is my code btw
    Code:
    <?php
    	session_start();	
    	include 'connect.php';
    	
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    
    
    <div id = "user">
    
    <?php 
        // this is where the select part that im having problem with
    
    	$sql="SELECT * from admin WHERE idno ='".$_SESSION['id']."'"; 
    		$container = mysql_query($sql);
    		while($row=mysql_fetch_array($container))
    		{					
    	echo $row['FNAME'].'<br/>';
        echo $row['LNAME'].'<br/>';
        echo $row['MNAME'].'<br/>';
        echo $row['IDNO'].'<br/>';
    	}
    							
    
    ?>
    
    
    
    </div>
    <div id = "userlink">
    <a href="user.php"><h2>View Profile</h2></a>
    <a href=""><h2>View Medical Record</h2></a>
    </div>
    <a href = "home.php">
    <div id="Layer1" style="position:absolute; left:784px; top:151px; width:61px; height:42px; z-index:1">
    </div>
    </div>
    <a href = "index.php"><div id = "logout"></div>
    </a>
    <div id="index"><img src="image/user%20page.jpg"></div>
    </body>
    </html>
    this is the connection
    Code:
    <?php
    $con = mysql_connect("localhost","root","") or die(mysql_error());
    $db = mysql_select_db("eng",$con);
    
    ?>
    and lastly this is where it checks the user logging in.
    Code:
    <?php
    session_start();
    	include 'connect.php';
    
    $user = $_REQUEST['user'];
    $pass = $_REQUEST['pass'];
    
    
    if($user && $pass)
    {
    $sql2="SELECT * FROM `admin` WHERE IDNO='$user' AND `IDNO`='$pass' AND ACCESS='admin'" ;
    $sql3="SELECT * FROM `admin` WHERE IDNO='$user' AND `IDNO`='$pass' AND ACCESS='patient'" ;
    $sql4="SELECT * FROM `admin` WHERE IDNO='$user' AND `IDNO`='$pass' AND ACCESS='doctor'" ;
    $query2=mysql_query($sql2) or die(mysql_error());
    $query3=mysql_query($sql3) or die(mysql_error());
    $query4=mysql_query($sql4) or die(mysql_error());
    //$query2=mysql_query($sql2) or die(mysql_error());
     
        if(mysql_num_rows($query2) > 0)
        {
          $row = mysql_fetch_assoc($query2);
          $_SESSION['id'] = $row['id'];
          //$_SESSION['username'] = $row['username'];
    	  
    	  echo "<script type=\"text/javascript\">window.location=\"admin.php\"</script>";
    	  //set user to on
    	//$sql3 =	"UPDATE `users` SET `status`='ON' WHERE `id`='".$_SESSION['id']."'";
    	//$res3 = mysql_query($sql3) or die(mysql_error());
    	 
    	 }else if(mysql_num_rows($query3) > 0)
    	 {
    	  $row = mysql_fetch_assoc($query3);
          $_SESSION['id'] = $row['id'];
          //$_SESSION['username'] = $row['username'];
    	  
    	  echo "<script type=\"text/javascript\">window.location=\"user.php\"</script>";
    	  
        }else if(mysql_num_rows($query4) > 0)
        {
          $row = mysql_fetch_assoc($query2);
          $_SESSION['id'] = $row['id'];
          $_SESSION['fullname'] = $row['firstname'];
          //$_SESSION['username'] = $row['username'];  
          echo "<script type=\"text/javascript\">window.location=\"doctor.php\"</script>";
    	
        }else
       {
        echo "<script type=\"text/javascript\">
    	alert(\"User Name or Password  is incorrect!\");
    	window.location=\"index.php\"</script>";
       }	
    }
    else
    {		
       echo "<script type=\"text/javascript\">
    	alert(\"You need to enter a ID number and Password!\");
    	window.location=\"index.php\"</script>";
    	
    }
    
    ?>
    any help would be appreciated

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    DEBUG DEBUG DEBUG.

    Code:
            $sql="SELECT * from admin WHERE idno ='".$_SESSION['id']."'"; 
            echo "DEBUG SQL: " . $sql . "<hr/>\n";
    
            $container = mysql_query($sql);
    What does the DEBUG show you?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    DEBUG DEBUG DEBUG.

    Code:
            $sql="SELECT * from admin WHERE idno ='".$_SESSION['id']."'"; 
            echo "DEBUG SQL: " . $sql . "<hr/>\n";
    
            $container = mysql_query($sql);
    What does the DEBUG show you?
    Hi thanks for the reply. it says
    DEBUG SQL: SELECT * from `admin` WHERE `idno`=''
    It seems that the value in the session isnt initialized. I think i have done the 'right' thing to do to put values in it so i really dont know what to do now, could you please help me fill that tiny missing field? i would really appreciate it.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    So start DEBUGGING the page where you (thought you) are putting a value *into* the Session.

    Put in lots of echo statements that will tell you where you got to and what you have done.

    I can't do this for you. I don't have control of your computer.

    One step at a time, you figure out what is going on and when and how.

    That's what programming is all about. If you can't debug, you can't program. 80% of commercial programming time is spent in testing and debugging, not coding.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    impacter (12-02-2011)

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    So start DEBUGGING the page where you (thought you) are putting a value *into* the Session.

    Put in lots of echo statements that will tell you where you got to and what you have done.

    I can't do this for you. I don't have control of your computer.

    One step at a time, you figure out what is going on and when and how.

    That's what programming is all about. If you can't debug, you can't program. 80% of commercial programming time is spent in testing and debugging, not coding.
    Hi, i have figured out whats wrong with my code thanks a bunch


  •  

    Posting Permissions

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