FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


POST a form in the Same page





therimalaya
I'm Doing a PHP Project Application, I want to sent the form data into the same page which should fetch record from database and display on the space just below the form. I've code the following, but when i click the submit button, it doesn't show any table, instead it refresh the page and comes to the initial condition.

I can not find what the problem is , please help me. Thank you
Code:

<?php
// Including Files
    include("Include/dbConnect.php");
      
//Creating Queries
   $rsSql="SELECT Name FROM myoffice";
      
// Fetching Records
   $sResult=mysql_query($rsSql,$conn) or die("Could Not Fetch Records");
    $rResult=mysql_query($rsSql,$conn) or die("Could Not Fetch Records");
    ?>
<form id="inputForm" name="inputForm" class="wufoo topLabel page" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" >
   <div id="header" class="info"><h2>IMAS Incoming and Outgoing Transaction Details</h2></div>
    <ul>
    <!-- SENDER DROPDOWN -->
      <li class="leftHalf" id="foli16" name="foli16">
         <div><span class="left">
            <label class="desc" id="title33" for="Field33"> Sender </label>
            <select id="sender" name="sender" class="field select addr" tabindex="1">
               <?php
                        while ($s_Office=mysql_fetch_array($sResult))
                        {
                            ?>
                                <option value="<?php echo $s_Office['Name']; ?>"><?php echo $s_Office['Name']; ?></option>
                            <?php
                        }
                    ?>
                </select>
         </span></div>
      </li>
   <!--RECEIVER DROPDOWN -->           
      <li class="rightHalf" id="foli" name="foli">
         <div><span class="left">
            <label class="desc" id="title34" for="Field5">Receiver</label>
            <select id="receiver"    name="receiver"    class="field select addr" tabindex="2"    >
               <?php
                        while ($r_Office=mysql_fetch_array($rResult)){
                    ?>
                        <option value="<?php echo $r_Office['Name']; ?>"><?php echo $r_Office['Name']; ?></option>
                    <?php
                    }
                    ?>
            </select>
         </span></div>
      </li>
        <li class="buttons ">
                <input type="image" src="/imasTesting/images/saveButton1.jpg" name="Submit" id="Submit" onclick=""/>
        </li>
    </ul>
</form>
<?php
   include_once("Include/dbConnect.php");
   if(isset($_POST['Submit'])){
      $sender=$_POST['sender'];
      $receiver=$_POST['receiver'];
      $query = "SELECT * FROM transaction WHERE Sender=\"$sender\" AND Receiver=\"$receiver\"";      
      $recordSource=mysql_query($query);
?>
      <table>
           <tr>
                <th>Transaction ID</th>
                <th>Sender Office</th>
                <th>Receiver Office</th>
                <th>Mail Number</th>
                <th>Date of Dispatch</th>
                <th>Number of Items</th>
                <th>Weight of Items</th>
            </tr>
<?php
      while($row=mysql_fetch_assoc($recordSource))
      {
?>
         <tr>
                <td><?php echo $row['transID']; ?></td>
                <td><?php echo $row['Sender']; ?></td>
                <td><?php echo $row['Receiver']; ?></td>
                <td><?php echo $row['mailNo']; ?></td>
                <td><?php echo $row['dispatchDate']; ?></td>
                <td><?php echo $row['itemNo']; ?></td>
                <td><?php echo $row['itemWt']; ?></td>
            </tr>
<?php           
      }
?>      
        </table>
<?php      
   }
?>
Marcuzzo
the problem is that $_POST["Submit"] is not set, and there for it will not display the table.

you are using a type="image" and I don't believe this one is posted to the server,
instead use a type="submit" that way you can actualy check if a form has been submitted by button click with the code
Code:
if(isset($_POST['Submit'])){


if you still want an image, you could pull this trick:
what you could do is to use a plain image link that submints the form with a little javascript.
like so:
Code:
<input type="submit" name="Submit" id="Submit" style="display:none;"/>

<a href="#" onclick="document.getElementById('Submit').click();"><img src=" [PATH TO PICTURE]" alt="" border="0" /></a>
jmraker
Or just use a hidden field
<input type="hidden" name="Submit" value="" />

Although with a <input type="submit" /> it should pass the X/Y coordinates of where in the image it was clicked, so it should pass submit_x and submit_y (or maybe just x and y in the post)
(php converts form names with dots to underscore: name="submit.y" becomes $_POST['submit_y'])

http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4.1
therimalaya
Thanks all, for suggestion,

I'll try these solutions right now...
Thanks again
Related topics
Help Apache problems
CSS - CSS Tutorial for skin maker
FAT32 or NTFS?
php problem
State your Political Philosophy! (1000 FRIH$ to the best!)
Login System Tutorial Part 1 Creating Registration
A poll that allows users to specify another option....
Spammers on FriHost
links on same page script - cant find one :(
Feed Back Form
Form validation, seperate file, or same as form?
Problem with a page in firefox.
proof we all didnt just "Happen" by chance.
should we care about antartic ice melting?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.