I'm having a problem in getting the value of the primary key of another table. Actually, I'm making an insert statement, but I've encountered a problem while inserting, so I make it looks like I'm only displaying what the user inputs on the previous page.... this is my tables/relation
create database db;
use db;
create table department
(deptID int not null auto_increment primary key,
deptname varchar(40),
location varchar(20)
);
create table faculty
(facID int not null auto_increment primary key,
facname varchar(30),
age int,
deptID int references department(deptID)
);
And this is my html code on the first page named list.html:
<html>
<head>
<title>A simple HTML form</title>
</head>
<body>
<form action="list2.php" method="POST">
<p><strong>Name:</strong><br>
<input type="text" name="name"></p>
<p><strong>Age:</strong><br>
<input type="text" maxlength="2" name="age"></p>
<p><strong>Department:</strong><br>
<input type="text" name="department"></p>
<p><input type="submit" value="send"></p>
</form>
And this is my code on the next page named list2.php:
<?php
include('dbconnect.php');
$name = $_POST[name];
$age = $_POST[age];
$department = $_POST[department];
$id = "select * from department where deptID = '$department'";
$query = mysql_query($id);
$iden = mysql_fetch_array($query);
echo "Name: " . $name . "</br>";
echo "Age: " . $age . "</br>";
echo "department: " . $department . "</br>";
echo "department's ID: " . $iden[deptID];
?>
By the way, here's my code on dbconnect.php:
<?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("db",$con);
?>
THIS IS THE OUTPUT AFTER I FILLED UP THE FORM:
Name: moonfang
Age: 19
department: math
department's ID:
As you can see... the value of department's ID is not displayed in the browser.... Why is that? is there something wrong on my code? Please help...![]()



Reply With Quote

Bookmarks