Forum Moderators: open
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<form method= "post" action="home.php">
<font face = "arial" size=0><b>Faculty ID</font><font size="5"></b>
<input name="submitFacultyIDnumber" size="17" value="<?echo $submitFacultyIDnumber;?>" maxlength="32" /></font>
<input type="submit" value="Submit">
<input type=reset value="Clear" name="reset"></td>
<body>
</body>
</html>
and here the query starts.
this is home.php file
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
$username = "#*$!XX";
$password = "#*$!#*$!XX";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("#*$!xx",$dbhandle)
or die("Could not select #*$!xx");
//execute the SQL query and return records
$ID=$_POST["submitFacultyIDnumber"];
$result = mysql_query("SELECT FacultyIDnumber,name,Office_location,Date_of_hiring,level FROM Faculty
WHERE FacultyIDnumber= '$ID'");
//fetch the data from the database
while ($r=mysql_fetch_array($result)) {
$FacultyIDnumber=$r["FacultyIDnumber"];
$name=$r["name"];
$Office_location=$r["Office_location"];
$Date_of_hiring=$r["Date_of_hiring"];
$level=$r["level"];
echo"$ID";
echo "$Faculty IDnumber<br> $name<br> $Office_location <br> $Date_of_hiring <br>$level <br>";";
}
//close the connection
mysql_close($dbhandle);
?>
<body>
</body>
</html>
[edited by: txbakers at 4:17 pm (utc) on Nov. 26, 2007]
[edit reason] removed username and password [/edit]
$username = "*******";
$password = "*******";
$hostname = "*******";
This along with a URL will allow someone full access to your database.
* Mods can you remove that for him?
Anyway on to your problem... The first thing I see that could be the issue is that the ID is quoted in the statement which would mean that it is a string. I am going to assume that it is an integer and needs to be unquoted.
Can you try this:
$result = mysql_query("SELECT FacultyIDnumber,name,Office_location,Date_of_hiring,level FROM Faculty
WHERE FacultyIDnumber= $ID");
All i did was remove the single quotes around the ID.
Try that, if it doesn't work post back with and error or what ever it returns.
Try moving this code between the <body></body>
<?php
$username = "#*$!XX";
$password = "#*$!#*$!XX";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("#*$!xx",$dbhandle)
or die("Could not select #*$!xx");
//execute the SQL query and return records
$ID=$_POST["submitFacultyIDnumber"];
$result = mysql_query("SELECT FacultyIDnumber,name,Office_location,Date_of_hiring,level FROM Faculty
WHERE FacultyIDnumber= '$ID'");
//fetch the data from the database
while ($r=mysql_fetch_array($result)) {
$FacultyIDnumber=$r["FacultyIDnumber"];
$name=$r["name"];
$Office_location=$r["Office_location"];
$Date_of_hiring=$r["Date_of_hiring"];
$level=$r["level"];
echo"$ID";
echo "$Faculty IDnumber<br> $name<br> $Office_location <br> $Date_of_hiring <br>$level <br>";";
}
//close the connection
mysql_close($dbhandle);
?>
[edited by: Demaestro at 5:19 pm (utc) on Nov. 26, 2007]
<?php
$username = "#*$!XX";
$password = "#*$!#*$!XX";
$hostname = "localhost";
alert('attempting connection');
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
alert('db handle = ' + $dbhandle);
alert('attempting to select DB');
//select a database to work with
$selected = mysql_select_db("#*$!xx",$dbhandle)
or die("Could not select #*$!xx");
alert('selected db = ' + $selected);
//execute the SQL query and return records
$ID=$_POST["submitFacultyIDnumber"];
alert('submited id = ' + $ID);
alert('attempting to execute query');
$result = mysql_query("SELECT FacultyIDnumber,name,Office_location,Date_of_hiring,level FROM Faculty
WHERE FacultyIDnumber= '$ID'");
alert('result = ' + $result);
alert('attempting to write values from db');
//fetch the data from the database
while ($r=mysql_fetch_array($result)) {
alert('in while loop');
alert('FacultyIDnumber = ' + $r["FacultyIDnumber"]);
$FacultyIDnumber=$r["FacultyIDnumber"];
alert('name= ' + $r["name"]);
$name=$r["name"];
alert('Office_location= ' + $r["Office_location"]);
$Office_location=$r["Office_location"];
alert('Date_of_hiring= ' + $r["Date_of_hiring"]);
$Date_of_hiring=$r["Date_of_hiring"];
alert('level= ' + $r["level"]);
$level=$r["level"];
alert($ID);
echo"$ID";
echo "$Faculty IDnumber<br> $name<br> $Office_location <br> $Date_of_hiring <br>$level <br>";";
alert('while loop end');
}
alert('out of while loop');
//close the connection
mysql_close($dbhandle);
?>
If you can do this it should give you a much better idea of what is happening line by line. If you can report back what it is telling you it will make it easier to debug.