Jump to content

Recommended Posts

Hi All,

 

I have a PHP form that submits data to the database table. Everything is working however, for the purpose of having a better structure in the table I would like to make a change.

 

On one part of the form the user would select a Visit Reason. If the user selects Sale they are given the "Primary" sales reasons from a dynamic drop-down box.

 

As a sale can contain more than one type of sale e.g handset/accessory I have also added additional tick boxes to add any additional items that may for part of that sale. Currently the "Primary" sale reason is writing to one column in my table, and then each of the tick boxes will also write to their own individual boxes. What this means is Accessory can be written as the primary reason, and then again in its own field in the table.

 

How can I get each of the fields from the drop-down to write to their individual table fields rather than have an additional field?

Also, is it able to activate the radio buttons only if sale is selected from the drop-down?

 

Here is my code below:

 

Form Page:

 

<!-- USERNAME IS CAPTURED TO TRACK WHICH USER IS CAPTURING THE REQUESTS -->
</td>
<td><input type="hidden" name="username" value="<?php echo "$username"; ?>"></td>
</tr>


<!-- INITIATOR E-MAIL ADDRESS RETRIEVAL - THIS FIELD CAN BE USED TO CAPTURE THE USER'S E-MAIL ADDRESS -->
<input type="hidden" name="email" readonly value="<?php echo $userinfo['email'];?>">


<!-- RANDOM REFERENCE NUMBER - THIS FIELD CAN BE USED TO PROVIDE THE USER WITH A REFERENCE NUMBER -->
<!-- <tr>
<!-- <td width="34%" align="right"><strong>Reference Number :</strong></td> -->
<!-- <td> -->
<input type="hidden" name="reference" readonly style="background-color: silver; color:#8B0000">
<!-- </td> -->
<!-- </tr> -->

<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
<tr>
<td align="right" width="100%"><br></td>
</tr>

</table>


<!-- CUSTOMER SEX SELECTION - RADIO BUTTON OPTION USED LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="40%"><strong>Gender :</strong></td>
<td width="10%"><input type="radio" name="gender" value="Female">Female</td>
<td width="10%"><input type="radio" name="gender" value="Male">Male</td>
<td width="40%"></td>
</tr>
</table>

<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
</table>


<!-- CUSTOMER ETHNIC GROUP SELECTION - DROP-DOWN OPTION USED LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td width="40%" align="right" valign="middle"><strong>Ethnic Group :</strong></td>
<td width="30%" align="left" valign="middle"><select name="ethnic_group" id="ethnic_group">
 <option value=""> --- Select an Option --- </option>
 <option value="African">African</option>	
 <option value="Asian">Asian</option>
 <option value="Coloured">Coloured</option>
 <option value="White">White</option>	
</select></td>
<td width="30%"> </td>
</tr>
</table>

<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
</table>


<!-- CUSTOMER AGE GROUP SELECTION - DROP-DOWN OPTION USED LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td width="40%" align="right" valign="middle"><strong>Age Group :</strong></td>
<td width="30%" align="left" valign="middle"><select name="age_group" id="age_group">
 <option value=""> --- Select an Option --- </option>
 <option value="< 18">< 18</option>	
 <option value="18 - 25">18 - 25</option>
 <option value="26 - 35">26 - 35</option>
 <option value="36 - 45">36 - 45</option>
 <option value="46 - 55">46 - 55</option>
 <option value="56 - 65">56 - 65</option>
 <option value="65 +">65 +</option>	
</select></td>
<td width="30%"> </td>
</tr>
</table>

<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
</table>

<!-- CUSTOMER REASON FOR VISITING STORE TIER 1 - DROP-DOWN OPTION USED LAST UPDATED ON 2012/10/17 -->

<table width="100%" border="0" align="center">
<tr>
<td width="40%" align="right" valign="middle"><strong>Reason For Customer's Visit :</strong></td>
<td width="30%" align="left" valign="middle"><select name="requirement" id="category" onchange="javascript: listboxchange1(this.options[this.selectedIndex].value);">
 <option value=""> --- Select an Option --- </option>
 <?php
 while ($requirement = mysql_fetch_array($result2)){
 ?>
 <option value="<?php echo $requirement['requirement']; ?>"><?php echo $requirement['requirement'];?></option>
 <?php
}
?>
</select></td>
<td width="30%"> </td>
</tr>
</table>

<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
</table>

<!-- CUSTOMER REASON FOR VISITING STORE TIER 2 PRIMARY - DYNAMIC DROP-DOWN OPTION USED LAST UPDATED ON 2012/10/17 -->

<table width="100%" border="0" align="center">
<tr>

<td width="40%" align="right" valign="middle"><strong>Reason Details :</strong></td>
<td width="15%" ="left" valign="middle"><script name="visit_detail" id="visit_detail" type="text/javascript" language="javascript">
			 document.write('<select name="visit_detail" onchange="javascript: listboxchange2(this.options[this.selectedIndex].value);"><option value="">--- Select an Option ---</option></select>')
</script></td>

<td width="10%" align="right" valign="middle"><strong>Handset Make :</strong></td>
<td width="35%" ="left" valign="middle"><script name="handset_make" id="handset_make" type="text/javascript" language="javascript">
			 document.write('<select name="handset_make" onchange="javascript: listboxchange3(this.options[this.selectedIndex].value);"><option value="">--- Select an Option ---</option></select>')
</script></td>
</tr>
</table>

<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
</table>


<!-- CUSTOMER REQUIREMENTS PART 2 - CHECK BOX OPTION USED LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="40%"><strong>Additional Visit Reasons :</strong></td>
<td width="10%"><input type="checkbox" name="accessory" value="Accessory">Accessory</td>
<td width="10%"><input type="checkbox" name="airtime" value="Airtime">Airtime</td>
<td width="40%"><input type="checkbox" name="handset" value="Handset">Handset</td>
</tr>

<tr>
<td width="40%"></td>
<td width="10%"><input type="checkbox" name="postpaid" value="Postpaid">Postpaid</td>
<td width="10%"><input type="checkbox" name="prepaid" value="Prepaid">Prepaid</td>
<td width="40%"></td>
</tr>
</table>
<!-- EMPTY TABLE USED FOR FIELD SPACING - LAST UPDATED ON 2012/10/17 -->
<table width="100%" border="0" align="center">
<tr>
<td align="right" width="100%"><br></td>
</tr>
</table>


<!-- CLOSING TABLE TAGS TO END FORM LAYOUT -->
</table>

<!-- SUBMIT BUTTON FUNCTION -->
<!-- OPENING TABLE TAGS TO OPEN SUBMIT BUTTON LAYOUT -->
<br>
<br>
<table width="100%" align="center" border="0">
<tr>
<td width="25%" align="center"></td>
<td width="25%" align="center"><input type="submit" value="Submit" name="submit"></td>
<td width="25%" align="center"><input type="reset" value="Reset Form" name="reset"></td>
<td width="25%" align="center"></td>
</tr>

<!-- CLOSING TABLE TAGS TO CLOSE SUBMIT BUTTON LAYOUT -->
</table>

<!-- CLOSING FORM TAG TO CLOSE FORM -->
</form>
</html>

 

Submit page:

 

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("store", $con);


$sql="INSERT INTO store_traffic
(username
, gender
, ethnic_group
, age_group
, requirement
, visit_detail
, accessory
, airtime
, handset
, postpaid
, prepaid
, handset_make)

VALUES
('$_POST[username]'
,'$_POST[gender]'
,'$_POST[ethnic_group]'
,'$_POST[age_group]'
,'$_POST[requirement]'
,'$_POST[visit_detail]'
,'$_POST[accessory]'
,'$_POST[airtime]'
,'$_POST[handset]'
,'$_POST[postpaid]'
,'$_POST[prepaid]'
,'$_POST[handset_make]'
)";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<b><font color='white' face='segoe' size='2'>1 record added</b></font>";
include "redirect_store.html";
mysql_close($con)
?>

Link to comment
https://forums.phpfreaks.com/topic/269673-form-data-entry/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.