SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form loses data on re-submit

    I have a form where the user chooses an item from the dropdown(Term) which then displays data(Rate) from the database. The user should be able to choose different terms to get the results however when you hit submit it works the first two times and then loses the data the third time. Also, when you first enter the page it has a specific Term(cid=1) that should be displayed. Does anyone know why it is losing the data?
    Code:
    <?php
    $calledforthefirsttime = true;
    ?>
    <?php
    if ($calledforthefirsttime == true)
    {
    	 
    $id = $_GET[id'];
    $sql = "SELECT * FROM table1 ORDER BY Display";
    $result = mysql_query($sql, $db)
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <select name="cid" id="cid">
                                             
    <?php
              while ($row=mysql_fetch_array($result)) 
    {
    
    if ($cid == $row[cid])
    {
    echo "<option value=\"$row[cid]\" selected>$row[Term]\n";
    }
    else
    {
    echo "<option value=\"$row[cid]\">$row[Term]";
    }
    }
    echo "</select>
    				
                   </select> <input type=hidden name=id value=$id> <input type='submit' name='button' id='button' value='Submit'> ";
    			
         ?>     
                                                                                                                                      
                                        
    </form>
            
     <?php
    $cid = 1;
    
     $sql3 = "SELECT * FROM table2 WHERE cid = '$cid' AND id='$id'";
    $result3 = mysql_query($sql3, $db);
    $row3 = mysql_fetch_assoc($result3);
    $cid = $_POST['cid'];
    $id = $_POST['id'];
    
     echo "Pricing 1: $row3[rate]";     
    }
    
     ?>                                       
    <?php
    
    if ((isset($_POST['cid'])) && ($cid!=""))
    {
    $cid = $_POST['cid'];
    
    $calledforthefirsttime = false;
    $id = $_POST['id'];
    	
    $sqlp="SELECT * FROM table2 WHERE cid = '$cid' AND id='$id'"; 
    $resultp = mysql_query($sqlp, $db);
    
    while ($rowp = mysql_fetch_array ($resultp))
    {
    
    echo "Pricing: $rowp[rate]";
    }
    		
    }
    
    ?>

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Firstly there are several syntax errors in your script that you need to address

    Why are you setting $calledforthefirsttime then checking it for the first routine, it will always be true and therefore always run !

    Im not 100% sure how this is supposed to run, I cant work out when pricing 1 should show and when pricing 2 should show
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •