Page 1 of 1

Cannot display item from database from specific user

Posted: Mon Apr 04, 2011 1:35 pm
by bleu_jade
I'm new to php,and i met some problem when displaying item from database. When user log in, i can retrieve and display username from database in page, but it failed to display when I try to retrieve and display relevant item related to the user at the same page...anyone can help???

/*1st: CAN NOT display item when assigned lecID=$id, which retrieve from input(log in)*/
<?php
include 'Connections/myconnection.php';
mysql_select_db($database_myconnection, $myconnection)
or die("Unable to connect to MySQL");
$query = "SELECT subCode FROM lecturer WHERE lecID=$id LIMIT 1";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result)) {
echo "{$row['subCode']}<br>" ;
}
?>
/*2nd: CAN display when assigned lecID=1133, which specified the user ID*/
<?php
include 'Connections/myconnection.php';
mysql_select_db($database_myconnection, $myconnection)
or die("Unable to connect to MySQL");
$query = "SELECT subCode FROM lecturer WHERE lecID=1133 LIMIT 1";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
echo "{$row['subCode']}<br>" ;
}
?>

Re: Cannot display item from database from specific user

Posted: Mon Apr 04, 2011 2:20 pm
by fugix
what is your $id set to?

Re: Cannot display item from database from specific user

Posted: Tue Apr 05, 2011 10:37 pm
by bleu_jade
$id = $_POST['userid']; but it was at another php file,as shown below. I tried to include the file inside,and it comes out with error...anyone can help???

<?php
session_start();

include 'Connections/myconnection.php';
mysql_select_db($database_myconnection, $myconnection)
or die("Unable to connect to MySQL");

$id = $_POST['userid'];
$password = $_POST['password'];

$result = mysql_query("SELECT Name FROM lecturer WHERE lecID='$id' and password='$password'")
or die(mysql_error());
if($data = mysql_fetch_object($result)){

$_SESSION["login"] = true;
$_SESSION["Name"] = $data->Name;
header('location:home.php');
}
else
header('location:login_Invalid.php');
?>