1

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>
3
  • Did you check print_r($_POST); Commented Feb 19, 2014 at 5:21
  • 1
    i dont see a hidden input anywhere in your posted script. Commented Feb 19, 2014 at 5:22
  • See the color difference up over there and fix the same. Commented Feb 19, 2014 at 5:24

2 Answers 2

1

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 . "'";
Sign up to request clarification or add additional context in comments.

3 Comments

hidden values are passed to another page, with using that using value iam not able to reteive data from database with select query in reteive.php
what does print_r($_POST) show you on the retrieve.php page?
it's correctly showing the value, but not able to reteive data from database. Select statement which I have written in retreive.php page is correct or wrong.
0
 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);
   }

12 Comments

i tried the value is correct only iam not able to retreive from database
echo $sql = "select * from active1active1 where Tno = '$Tno'"; die(); this will print query in your browser.try to run this query in your phpMyadmin to verify query
in phpMyadmin the results are perfect
i have editied my answer please try with this, i have removed if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }
after removing also that retreiving data is not done.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.