Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Sending data from a drop down box to a MySql database
Old 09-23-2008, 03:08 PM Sending data from a drop down box to a MySql database
Novice Talker

Posts: 13
Location: UK
Trades: 0
Hi,

Can someone explain to me, how to send data selected from a dropdown menu into a MySQL database, I understand how the coding would work, but not when you have several choices to pick from as shown:-

PHP Code:
Choose the Type of Issue
<select name="dropdown" Id="dropdown">
  <
option value="General">General</option>
  <
option value="Server">Server</option>
  <
option value="Database">Database</option>
  <
option value="Environment">Environment</option>
  <
option value="Requirement">Requirement</option>
</
select
I'd like to understand how I could fit in these options. I understand you must post it like this:-
PHP Code:
// Get values from form 
 
$comments=$_POST['']; 
And I'm guessing this [''] would contain the name of the form, in this case 'dropdown' if im right? but not sure what the ID can be used for as above?

I am also guessing a if statement maybe required based on the option selected by the user, and the particular option selected has that 'string' sent into the database, for example in my previous post:

PHP Code:
if ($priority != NULL) { 
$priority 1

else { 
$priority 0

patelh5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-23-2008, 03:36 PM Re: Sending data from a drop down box to a MySql database
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
And I'm guessing this [''] would contain the name of the form, in this case 'dropdown' if im right? but not sure what the ID can be used for as above?
The name of the form element is what would be in quotes, but you are correct in saying it would be "dropdown".

The element ID attribute is not used in HTTP requests but can be used should you need to read from or write to the element using javascript.

var myValue = document.formname.elementname.value
var myValue = document.forms["formname"].elements["elementname"].value
var myValue = document.getElementById("elementid").value

Are all valid methods of reading the value of a <input> element.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-23-2008, 04:38 PM Re: Sending data from a drop down box to a MySql database
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
You should examine the POST array with print_r or var_dump as it will help you understand whats happening when you submit a form.

For example if you submit a form containing your dropdown list and echo out the POST array you will see:

Code:
Array
(
   
    [dropdown] => General
    
)
That is the POST array contains a key of 'dropdown' and a value of 'General'. You would access this value using $_POST['dropdown'].
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-23-2008, 05:05 PM Re: Sending data from a drop down box to a MySql database
Novice Talker

Posts: 13
Location: UK
Trades: 0
Right ok, sorry I didn't understand that much. But when im reading those elements from those methods, how would that all fit into this section of my code:-

PHP Code:
// Get values from form 
 
$comments=$_POST['comments'];
 
$priority=$_POST['priority']; 
Need more explanation on this, I am sure it is possible to do all the inserting into a database in PHP, just retrieving those separate value options is the difficult part!
patelh5 is offline
Reply With Quote
View Public Profile
 
Old 09-23-2008, 06:41 PM Re: Sending data from a drop down box to a MySql database
Novice Talker

Posts: 13
Location: UK
Trades: 0
Oh sorry, ignore my above reply to the previous member. Um I read up on all that you told me to on print_r. Would I first need to set the values in an array like:-

<pre>
<?php
$a
= array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'
));
print_r ($a
);
?>
</pre>
patelh5 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Sending data from a drop down box to a MySql database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47923 seconds with 12 queries