Jump to content

Help Please - How do i store data from a ComboBox


I3erk

Recommended Posts

I am quite new to web programming and i am trying to make a ComboBox for my website.

 

I have looked online, but i was unable to find anything on how to do this.

 

 

This ComboBox will be on a promo page for the website.

 

Right now, i created the ComboBox and it works perfectly. 

 

The next thing i want to do are 2 things (and have them done simultaneously):

 

1. when the submit button is clicked, i want it to store whatever is selected in the ComboBox into a database/spreadsheet, in order to determine the number of times the option is selected.

 

2. when the submit button is clicked, the client will then get sent to the website homepage.

 

Can anyone point me in the right direction as to how i can go about doing this?

 

Thanks.

 

I3erk

 

<form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com">
      <select name="frmhowhear" id="frmhowhear">
<option value="">Select one…</option>
<option value="Courrier Laval">Courrier Laval</option>
<option value="L'Étoile">L'Étoile</option>
<option value="Le Progress">Le Progress</option>
<option value="Le Richelieu">Le Richelieu</option>
<option value="Le Mirabel">Le Mirabel</option>
<option value="L'Information du Nord">L'Information du Nord</option>
<option value="Le Regional">Le Regional</option>
<option value="The Gazette">The Gazette</option>
<option value="Tremblant Express">Tremblant Express</option>
<option value="La Flèche">La Flèche</option>
<option value="Brochure">Brochure</option>
<option value="Recommendation">Recommendation</option>
      </select>

Link to comment
Share on other sites

It has to be on the same page:

If you want to use it on another page use:

<?php
$_SESSION['WhateverNameYouLike'] = $_POST['frmhowhear'];
?>

 

But you got to remember to use

 

<?php
     session_start();
?>

 

on each page u use the session variable

And to redirect to another page use this

 

<?php
if (isset($_POST['WhateverYourButtonsNameIs'])) { 
     header('Location: http://www.example.com/');
}
?>

Link to comment
Share on other sites

there are 3 ways i no of to send data from 1 page to anouther

_post

_get

sessions

 

since u have a form _post will work fine for u

 

change

<form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com">

to

<form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com/test.php">

 

this will echo the value selected. u just need to create a mysql table and run an insert query.

test.php

 

<?php

$var = $_POST['frmhowhear'];

 

echo $var ;

?>

Link to comment
Share on other sites

Hyster,

 

if i change

<form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com">

to

<form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com/test.php">

 

Wont it take the clients to the test.php page instead of sending them to the homepage upon clicking the submit button?  Is there a way to do both? (ie: have 2 actions for 1 button, such as storing the selected option into a table on a new page, while still sending the client to the website homepage)

Link to comment
Share on other sites

not tested this but i dont think it will be far wrong

 

<form id="form1" name="form1" method="get" action="http://www.maisonsbellevue.com/index.php">      
<select name="frmhowhear" id="frmhowhear">	
<option value="">Select one…</option>	
<option value="Courrier Laval">Courrier Laval</option>	
<option value="L'Étoile">L'Étoile</option>	
<option value="Le Progress">Le Progress</option>	
<option value="Le Richelieu">Le Richelieu</option>	
<option value="Le Mirabel">Le Mirabel</option>	
<option value="L'Information du Nord">L'Information du Nord</option>	
<option value="Le Regional">Le Regional</option>	
<option value="The Gazette">The Gazette</option>	
<option value="Tremblant Express">Tremblant Express</option>	
<option value="La Flèche">La Flèche</option>	
<option value="Brochure">Brochure</option>	
<option value="Recommendation">Recommendation</option>      
</select>
<input type="submit"/>
</form>


<?php
//database connection info
$host="localhost"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
  


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("table_name")or die("cannot select DB");


if (isset($_GET['frmhowhear'])) { 

$var = $_GET['frmhowhear']; 

// update data in mysql database 
$sql="INSERT INTO $tbl_name (rsku) values 
('$var')";
$result=mysql_query($sql);


// if successfully updated. but dont need it

if($result){
echo "Update Successful";

}
else {
echo "ERROR"; 
}
}
?>

Link to comment
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.