Cannot display item from database from specific user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bleu_jade
Forum Newbie
Posts: 6
Joined: Sat Apr 02, 2011 11:42 am

Cannot display item from database from specific user

Post 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>" ;
}
?>
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Cannot display item from database from specific user

Post by fugix »

what is your $id set to?
bleu_jade
Forum Newbie
Posts: 6
Joined: Sat Apr 02, 2011 11:42 am

Re: Cannot display item from database from specific user

Post 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');
?>
Post Reply