tags:

views:

35

answers:

2

i want to get value from database..for exmaple,in the name field, it show the name that stored in the database. i want to show the value in the respective field.but it cannot retrieve the value..plz guys..help me

<?php 
    session_start();
    $username = $_SESSION["username"];
    $department = $_SESSION["department"];

?>
<html>
<head>
<title>Change Password</title>

</head>

<form method="post"  action="changepassprocess.php">
<?php
$db = mysql_connect('localhost','root') 
    or die ("unable to connect");
    mysql_select_db('fyp',$db) or die ("able to select");

$sql_select = "SELECT * FROM access WHERE username ='".$username."' ";
?>

<font face= "arial" size="2" font color="black">
<center>
<h3 align=center> Change Password </h3>
<table width="500" height="100" border="0" cellspacing="0" cellpadding="2">

<tr>
      <tr>
           <td align="left">User ID</td>
           <td>: <input name="username" type="text" id="username" value="<? {echo "$username"; } ?>" size="20" maxlength="10" readonly='username'></td>
      </tr>  

      <tr>
        <td align="left">Name </td>
        <td>: <input name="name" type="text" id="name" value="<? {echo "$name"; } ?>" size="50" readonly="name"></td>
    </tr>       

         <tr>
           <td align="left">Department  </td>
           <td>: <?php echo $row['department']; ?> </td>      
         </tr>

         <tr>
           <td align="left">New Password </td>
           <td>:<input name="newpassword" type="password" id="newpassword" size="20" ></td>
      </tr>

</table><br>  
    <align = center><input type="submit" name="send" value="Change Password">
</form>
</body>
</html>
+2  A: 

Well, you forgot to run your query to the database. The $sql_select variable holds the query text, but you need to pass it to the database and retrieve the answer from it. Read http://php.net/manual/en/function.mysql-query.php and examples there.

n1313
+2  A: 

You are missing:

$result = mysql_query($sql_select);
$row = mysql_fetch_array($result);

These will execute the query you've prepared and get the results as an array $row.

You might want to see how get fetch a value from Mysql DB using php from:

W3school: Select Data From a Database Table.

codaddict
i have put the statement..but the value still not appear
You must perform some error checking after these statements.
codaddict