1.11M Members

submitted in the same form and database

 
0
 

Hello there. This is what I'm trying to do. When user click at the firs drop down button which contain the location of the school, that button will retrieve data from database and it will appear at the same page of the button. The problem that I'm having right now is, how am I suppose to save the value starting from location until payment inside of database. I try to seperate the form but, some data didn't enter the database. When I put it all in the same form, when the confirm button is click, it redirect to the same page and there is no data enteres in the database. This is my code.

<html>
<body>
<?php 

session_start();
$user=$_SESSION['user_id'];

?>


<table width="1281" height="351" border="1" <form name="book" method="post" >bordercolor="C0F7FE" bgcolor="E9F1EA">
  <tr>   
    <td valign="top" height="175">


    Select School<br><br>
        <select onChange="submit()" name="school">
        <?php 

        $school = array(' ' => 'SELECT',
                        '1' => 'SMK Seri Pantai',
                        '2' => 'SMK Tengku Sulaiman',
                        '3' => 'SMK Convent Butterworth',
                        '4' => 'SMK Dato Megat Khas');

        foreach($school as $value => $caption)
        {       
            echo "<option value='$value'>$caption</option>";
        }   
        ?>    </select>    

<?php

$next=$_POST['school'];

$conn = mysql_connect("localhost", "root", "") or die ("Could not connect to server");
$db = mysql_select_db("Smartlocker", $conn) or die ("Could not connect to database");
$sql = "SELECT * FROM locker WHERE category_id='$next' ";
$result = mysql_query($sql) or die ("Could not execute query");
?>

<?php 
if($myrow=mysql_fetch_row($result))
{

echo "
<table width='600' border='1' bordercolor='C0F7FE'>
    <tr><td></td>
        <td><center><strong>School</strong></center></td>
        <td><center><strong>Locker No.</strong></center></td>     
        </tr>";

do{
echo "
    <tr><td><input type='radio' name='check' value='$myrow[3]'>    </td>    
        <td>$myrow[2]</td>
        <td><center>$myrow[3]</center></td>         
    </tr>";

}
while($myrow=mysql_fetch_row($result));

echo "</table>";

?>

<br>
<table width="270" border="0">
  <tr>
    <td>Number of day to book : </td>
    <td><select>
        <?php 

        for($i=1; $i<=30; $i++)
        {
            echo "<option value='$i'>$i</option>";
        }
        ?>
        </select> day(s)
    </td>
  </tr>
</table>

<br>

<table width="270" border="0">
  <tr>
    <td>From</td>
    <td><select>
        <?php 

        for($a=01; $a<=31; $a++)
        {
            echo "<option value='$a'>$a</option>";
        }
        ?>
        </select></td>
    <td><select>
        <?php 

        $month = array('01' => 'January',
                       '02' => 'February',
                       '03' => 'March',
                       '04' => 'April', 
                       '05' => 'May',
                       '06' => 'June',
                       '07' => 'July',                     
                       '08' => 'August', 
                       '09' => 'Sepytember', 
                       '10' => 'October',
                       '11' => 'November',
                       '12' => 'December');

        foreach($month as $value => $bulan)
        {
            echo "<option value='$value'>$bulan</option>";
        }
        ?>
        </select></td>
        <td><select>
        <?php 

        for($b=2012; $b<=2050; $b++)
        {
            echo "<option value='$b'>$b</option>";
        }
        ?>
        </select></td>
  </tr>
  <tr>
    <td>To</td>
    <td><select>
        <?php 

        for($c=01; $c<=31; $c++)
        {
            echo "<option value='$c'>$c</option>";
        }
        ?>
        </select></td>
    <td><select>
        <?php 

        $month2 = array('01' => 'January',
                        '02' => 'February',
                        '03' => 'March',
                        '04' => 'April', 
                        '05' => 'May',
                        '06' => 'June',
                        '07' => 'July',                    
                        '08' => 'August', 
                        '09' => 'Sepytember', 
                        '10' => 'October',
                        '11' => 'November',
                        '12' => 'December');

        foreach($month2 as $value2 => $bulan2)
        {
            echo "<option value='$value2'>$bulan2</option>";
        }
        ?>
        </select></td>
    <td><select>
        <?php 

        for($d=2012; $d<=2050; $d++)
        {
            echo "<option value='$d'>$d</option>";
        }
        ?>
        </select></td>
  </tr>
</table>

<br>
Payment can only be made through :<br>
<input type='radio' name='pay' value='BankDeposit'> Bank Deposit<br>

<table width="600" border="0">
  <tr>
    <td><div align="right">

    <input type='submit' name='submit' value='Confirm'>
    </div></td>
  </tr>
</table>

<?php } ?>
    </td>
  </tr>
</table>
</form>
</body>
</html>
 
0
 

line 11, the <form> is in the middle of <table> so won't work.

 
0
 

yea. I know that. I accidently drag it there in this post.

 
0
 

Theres no name attribute on any of the select boxes

<select name='databasecol'>




while($row = mysql_fetch_assoc()){//while looping through each database row
    echo "<input type='hidden' name='unqid'' value='{$row['unique_id']}'/>\r\n";
    echo "<input type='hidden' name='form_submit' value='SUBMITTED'/>\r\n";//may want to create a random token instead to prever multi submitting
    //inputs name= db_field_name

}


//top of page
if(ISSET($_POST['form_submit']) && $_POST['form_submit'] == 'SUBMITTED'){
    //get fields out and write into sql query to write into the db
    //run query
    //redirect to thank you page or next step
}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: