Reputation: 11
After passing a php variable(Tno) from one page to another page using button with hidden value, with that variable(Tno) tried to retrieve the data from the database, but I am not able to retrieve with that variable i.e. Tno. I had attached form1.php and retrieve.php.
form1.php
<?php
session_start();
?>
<?php
if( isset ($_SESSION["Email"])) {
$con=mysql_connect("localhost","admin","password");
// Check connection
if (!$con)
{
//echo "i am not ale to connect.<br>";
die('Could not connect: ' . mysql_error());
}
else{
//echo " i am able to connect.<br>";
}
mysql_select_db("maintable", $con);
$Email = mysql_real_escape_string($_SESSION['Email']);
$sql1="select * from customer where Email=('$Email')";
$result1=mysql_query($sql1);
while($row = mysql_fetch_array($result1)){
$var1 = $row['Identity'];
}
//echo" Email of the customer = $Email.<br>";
//echo "identity of the customer = $var1.<br>";
$sql2= "SELECT * FROM `suptest` WHERE Tno LIKE '$var1%'";
$result2=mysql_query($sql2); ?>
<table border=0 width=50%>
<tr>
<th>Ticket Ref. No.</th> <th>Subject</th><th>Status</th></tr>
<?php
while($row = mysql_fetch_array($result2)){
$ticketno= $row['Tno'];
?>
<form action="retrieve.php" method="post">
<tr><td><?php echo $row['Tno']; ?><input type="text" value="<?php echo $row['Tno']; ? >" name="Tno" /></td>
<td><?php echo $row['sub']; ?></td>
<td><?php echo $row['status']; ?></td>
<td><input type="Submit" value="Update" /></td></tr>
</form>
<?php
} ?>
</table>
<?php
mysql_close($con);
}
?>
<?php
session_start();
?>
<html><head></head>
<body>
<?php
$con=mysql_connect("localhost","admin","password");
//echo "Check connection";
if (!$con)
{
//echo "I am not ale to connect.<br>";
die('Could not connect: ' . mysql_error());
}
else{
//echo "I am able to connect.<br>";
}
mysql_select_db("maintable", $con);
$Tno = mysql_real_escape_string($_POST['Tno']);
//echo "my tno is $Tno.<br>";
$Email = mysql_real_escape_string($_SESSION['Email']);
echo $Email;
$sql = "select * from `active1active1` where Tno = ('$Tno')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$result=mysql_query($sql);
echo $result;
echo mysql_num_rows($result);
echo "entering while loop";
while($row=mysql_fetch_array($result))
{
echo "entered while loop";
echo $row['Tno'] . "<br />";
echo $row['Email'] . "<br />";
echo $row['pdesc'] . "<br />";
echo $row['Activity'] . "<br />";
}
?>
</body></html>
Upvotes: 1
Views: 3122
Reputation: 3314
value="<?php echo $row['Tno']; ? >
There should not be any space after ? change to ?>
<form action="retreive.php" method="post">
<tr>
<td>
<input type="hidden" value="<?php echo $row['Tno']; ?>" name="Tno" />
</td>
<td>
<input type="Submit" value="Update" />
</td>
</tr>
</form>
retrie` try this simply:
$Tno = mysql_real_escape_string($_POST['Tno']);
echo $sql = "select * from `active1active1` where Tno = '$Tno'";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
print_r($row);
}
Upvotes: 0
Reputation: 2522
im going to take a stab here:
this line
<tr><td><?php echo $row['Tno']; ?><input type="text" value="<?php echo $row['Tno']; ? >" name="Tno" /></td>
should be this?
<tr><td><?php echo $row['Tno']; ?><input type="hidden" name='Tno' value="<?php echo $row['Tno']; ? >" name="Tno" /></td>
note i added type=hidden and a name for the input
try:
$sql = "select * from `active1active1` where Tno = '" . $Tno . "'";
Upvotes: 1