...

View Full Version : Problem with using SELECT



impacter
11-30-2011, 03:39 AM
Hi guys. i have this problem that i cant seem to fix. the select * from isnt showing anything.. here is my code btw


<?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


<?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.


<?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 :)

Old Pedant
11-30-2011, 06:24 AM
DEBUG DEBUG DEBUG.



$sql="SELECT * from admin WHERE idno ='".$_SESSION['id']."'";
echo "DEBUG SQL: " . $sql . "<hr/>\n";

$container = mysql_query($sql);

What does the DEBUG show you?

impacter
11-30-2011, 07:26 AM
DEBUG DEBUG DEBUG.



$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.

Old Pedant
11-30-2011, 09:02 PM
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.

impacter
12-02-2011, 08:07 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum