i type the following code....
it runs properly....data gets fetch but i am not able to display it in a textbox....
it simply remains blank....whereas i am able to fetch the data outside the form tags

here is my code:
here i can see name =himanshu outside the form but in the inside the textbox remain blank

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
div
{
font-size:18px;
}
    BODY {
max-width : 900px;
margin-left:auto;
margin-right:auto;
} 
</style>
    <title></title>
</head>
<body>
<?php
define('DB_USERNAME', 'akshay');
define('DB_PASSWORD', 'akshay321');
define('DB_DATABASE', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.13.213)(PORT=1521)) (CONNECT_DATA=(SERVER=DEDICATED) (SERVICE_NAME = orcl)))');
$conn= oci_connect(DB_USERNAME, DB_PASSWORD, DB_DATABASE)
or die(oci_error());
echo "success...";
example_query($conn);

 function example_query ($conn) {

    // Parse a query containing a bind variable.
    $stmt = oci_parse($conn, "SELECT * ".
                             "FROM   him_details ");

    // Execute the completed statement.
    oci_execute($stmt, OCI_DEFAULT);

    while (oci_fetch($stmt))
	 {
    	$name    = oci_result($stmt, "NAME");
    	$branch    = oci_result($stmt, "BRANCH");
    	$smobile      = oci_result($stmt, "SMOBILE");
    	$eno      = oci_result($stmt, "ENO");
    	$hostel = oci_result($stmt, "HOSTEL");
    	$room      = oci_result($stmt, "ROOM");
    	$fmobile     = oci_result($stmt, "FMOBILE");
    	$address  = oci_result($stmt, "ADDRESS");
echo "name=$name "; 	
}
	}

?>
<div style="position:absolute; width:900px; height:900px; border: 2px solid #000000;">
<div>
<table width="900" height="98" border="1" cellpadding="0" cellspacing="0" bordercolor="#000066" bgcolor="#ffcc00" align="center">
  <tr>
    <td width="900" nowrap rowspan="8"><p align="center" class="style1"> <IMG align=absMiddle src="PS.jpg" width=89 height=87>   <span class="style2">SIR PADAMPAT SINGHANIA UNIVERSITY</span></p></td>
  </tr>
</table>
</div>
<form id="form1" runat="server">
      
    
<div style="position:absolute; width:400px; height:325px; top:150px; left:225px;">
<label style="float:left; border-left-width:thick;">Name:</label>&nbsp;

<input style="float:right; border-right-width:thick" name="name" type="text" value="<?php echo $branch;?>" />  
<br /><br />
<label style="float:left; border-left-width:thick;">Branch:</label>
<input style="float:right; border-right-width:thick" name="branch" type="text" value="<?php echo $branch;?>" />

<br /><br />
<label style="float:left; border-left-width:thick;">Student Mobile No.</label>
<input style="float:right; border-right-width:thick" name="mobile_no" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Enrollment No.</label>
<input style="float:right; border-right-width:thick" name="enroll_no" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Hostel No.</label>
<input style="float:right; border-right-width:thick" name="hostel_no" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Room No.</label>
<input style="float:right; border-right-width:thick" name="room_no" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Father's/Gardian no.</label>
<input style="float:right; border-right-width:thick" name="guardin_no" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Address</label>
<textarea style="float:right; border-right-width:thin; resize:none" type="text" name="" cols="16" rows="2"></textarea>
<br />
    <br />
</div>
<input name="student_image" style="position:absolute; top:150px; left:700px"  width="150" height="150" type="image" id="student_image" src="200x200.jpg" align="right" />

<hr align="right" style="position:absolute; top: 500px; height: 0px;" width="900" 800px" />

<div id="fill_outpass" style="position:absolute; width:400px; height:325px; top:600px; left:225px;">
<label style="float:left; border-left-width:thick;">Date:</label>&nbsp;
<input style="float:right; border-right-width:thick" id="date" name="date" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Out Date:</label>&nbsp;
<input style="float:right; border-right-width:thick" name="out_date" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">Out Time</label>&nbsp;
<input style="float:right; border-right-width:thick" name="out_time" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">In Date:</label>&nbsp;
<input style="float:right; border-right-width:thick" name="in_time" type="text" />
<br /><br />
<label style="float:left; border-left-width:thick;">In Time:</label>&nbsp;
<input style="float:right; border-right-width:thick" name="in_time" type="text" />
<br /><br />
</div>


<div style="position:absolute;width:200px; height:100px; top:850px; left:225px;" >
<input name="Submit" type="button" style="float:left" value="Submit" />
&nbsp;
 <input name="Reset" type="button" style="float:right" value="Reset" />
</div>
</form>
</div>

</body>
</html>

Recommended Answers

All 6 Replies

its obvious you cannot, because you are echoing $branch in name tag :)

sry....its name dere...but still nothing is coming in o/p.
atleast branch shoould be displayed.
n sry for the wrong code...

Its because when u cconnect to your db u set the host as Localhost maybe

can you see name=himanshu if you put echo statement outside the while loop??

finally i understood.....
the problem was with the scope of the functions.
i was not able to access the variables outside the functions...
i removed it and it works fine now :D
Thanks for your replies bhailog :D

I rewrote the code for mysql, its almost same as oracle, maybe you could learn something from it?


SQL data

CREATE TABLE IF NOT EXISTS `him_details` (
  `NAME` varchar(25) DEFAULT NULL,
  `BRANCH` varchar(25) DEFAULT NULL,
  `SMOBILE` int(11) DEFAULT NULL,
  `ENO` int(11) DEFAULT NULL,
  `HOSTEL` varchar(25) DEFAULT NULL,
  `ROOM` varchar(25) DEFAULT NULL,
  `FMOBILE` int(11) DEFAULT NULL,
  `ADDRESS` varchar(25) DEFAULT NULL
)

INSERT INTO `him_details` (`NAME`, `BRANCH`, `SMOBILE`, `ENO`, `HOSTEL`, `ROOM`, `FMOBILE`, `ADDRESS`) VALUES
('first user', 'london', 123456789, 1, 'hostel', '22', 123456789, 'london, uk'),
('second user', 'oxford', 2147483647, 2, 'hotel', '14', 564789123, 'oxford, uk');

PHP

<?php
	$details = array(); 
	$username ='root';
	$password = '';
	$server =  'localhost';
	$database = 'orcl';
	$connection =  @mysql_connect($server,$username,$password);
	if($connection) {
		$db = @mysql_select_db($database);
		if($db){
			$query = @mysql_query("SELECT * FROM him_details");
			if($query){
				$details = @mysql_fetch_array($query);
			}
			else {
				die(mysql_errno()." ".mysql_error());
			}
			
		}
		else {
			die(mysql_errno()." ".mysql_error());
		}
	}
	else {
		die(mysql_errno()." ".mysql_error());
	}
?>

<html>
	<head>
		<title>
			Demo
		</title>
	</head>
	<body>
		<table>
			<tr>
				<td width="45%">
					Name
				</td>
				<td>
					<input type="text" value="<?php echo $details[0];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Branch
				</td>
				<td>
					<input type="text" value="<?php echo $details[1];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Smobile
				</td>
				<td>
					<input type="text" value="<?php echo $details[2];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Eno
				</td>
				<td>
					<input type="text" value="<?php echo $details[3];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Hostel
				</td>
				<td>
					<input type="text" value="<?php echo $details[4];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Room
				</td>
				<td>
					<input type="text" value="<?php echo $details[5];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Fmobile
				</td>
				<td>
					<input type="text" value="<?php echo $details[6];?>" disabled="true"></input>
				</td>
			</tr>
			<tr>
				<td>
					Address
				</td>
				<td>
					<input type="text" value="<?php echo $details[7];?>" disabled="true"></input>
				</td>
			</tr>
		</table>
	</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.