PHP/MySQL Form Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slaterino
Forum Commoner
Posts: 46
Joined: Fri Jul 11, 2008 10:50 am

PHP/MySQL Form Query

Post by slaterino »

Hi,
I have created a form below which has a number of radio buttons. The user selects one of the buttons then clicks next to go a different form (enrol2.php). However, I need it to work so that some of the radio buttons go to a sub-form first where they have a number of choices before getting to the final form (enrol2.php). All the data comes from a MySQL database and I want to create a CMS for this also. What is the best way to do this?

For instance, should I create another table in the database with two fields ($cou_name and the sub-choice one, which i'll call $cou_sub). Then when a button is selected it would query whether $cou_name is present in the new table. If it is, it would list all $cou_sub entries as radio buttons that have the specific $cou_name in their entry.

Would all this be done on the second page, enrol2.php? Would this be the best way of setting this up? Sorry if this doesn't make complete sense! I find it quite hard to describe these things. Here are the forms:

BTW, I will start using session_start() soon so I can make the code a lot more manageable.

enrol.php

Code: Select all

<form method="post" action="enrol2.php">
<?php
include 'library/config.php';
include 'library/opendb.php';
 
$query  = "SELECT cou_ID, cou_name, cou_price 
           FROM courses
           ORDER BY cou_name ";
$result = mysql_query($query);
 
while(list($cou_ID, $cou_name, $cou_price)= mysql_fetch_row($result)) 
{
    echo "<input type='radio' value='$cou_ID' name='txt_course'>$cou_name - £$cou_price<br />";
    echo "<input type='hidden' value='$cou_name' name='txt_coursename'>";
    echo "<input type='hidden' value='$cou_price' name='txt_price'>";
}
 
include 'library/closedb.php';
?>
<input type="submit" value="Next">
</form>
enrol2.php

Code: Select all

<?php
include 'library/config.php';
include 'library/opendb.php';
 
$mtx_course=$_POST['txt_course'];
$mtx_coursename=$_POST['txt_coursename'];
$mtx_price=$_POST['txt_price'];
?>
<h2><?php echo "$mtx_coursename"; ?> - Price <?php echo "$mtx_price"; ?></h2>
<?php
 
$query  = "SELECT cl_ID, cl_course, cl_day, cl_date, cl_time, cl_location, cl_map
           FROM classes
           WHERE cl_course = $mtx_course
           AND cl_date between CURRENT_DATE and CURRENT_DATE + interval 0.5 year
           ORDER BY cl_date ";
$result = mysql_query($query);
 
while(list($cl_ID, $cl_course, $cl_day, $cl_date, $cl_time, $cl_location, $cl_map)= mysql_fetch_row($result)) 
{
    list($year, $month, $day)=split("-",$cl_date);
    $cl_date = date('j M Y', mktime(0, 0, 0, $month, $day, $year));
    
    echo "<form method='post' action='enrol3.php'>";
    echo "<input type='hidden' name='txt_coursename' value='$mtx_coursename' />";
    echo "<input type='hidden' name='txt_location' value='$cl_location' />";
    echo "<input type='hidden' name='txt_date' value='$cl_date' />";
    echo "<input type='hidden' name='txt_time' value='$cl_time' />";
    echo "<input type='hidden' name='txt_price' value='$mtx_price' />";
    echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='courseDetail'>";
    echo "<tr><td class='courseTitles'><p><strong>Location:</strong></p></td>";
    echo "<td><p>$cl_location</p></td>";
    echo "<td align='right'><p><a href=\"$cl_map\" target='_blank' title='View a map of this location' class='mapLink'>[View Map]</a></p></td></tr>";
    echo "<tr><td><p><strong>Date:</strong></p></td><td><p>$cl_day $cl_date</p></td><td>&nbsp;</td></tr>";
    echo "<tr><td><p><strong>Session Times:</strong></p></td><td><p>$cl_time</p></td>";
    echo "<td align='right'><input type='submit' value='enrol' /></td></tr></table>         </form>";
}
 
include 'library/closedb.php';
?>
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: PHP/MySQL Form Query

Post by aceconcepts »

Information overload!!!!

Try starting with your first objective - don't speak your mind!
Post Reply