Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 5th Oct 2012, 12:29 PM   #1
TNT
 
otfromtot's Avatar
 
Join Date: 2012
Location: florida
Posts: 65
Thanks: 19
Thanked 5 Times in 5 Posts
Default
Multiple form fields to one database column
Share on: 
fb share twitter share gplus share more share

its a simple enough form, uses method="post"
the issue is that i have several text inputs that need to all submit to "customer_comments" but when i name them all "customer_comments" only the final one ends up being seen in the database.
im trying to do php to handle it but there seems to be issues
<?
$customer_comment = "";
foreach($_POST['customer_comment'] as $value)
{
$customer_comment .= $value . ", ";
}
$customer_comment = substr($customer_comment, 0, -2); //to get rid of the final ", "
echo $customer_comment;
?>
right now, instead of posting customer comment,customer comment, customer comment it's just posting "Array"
otfromtot is offline  
Unread 5th Oct 2012, 10:42 PM   #2
QA Manager - I Hate Bugs!
 
Join Date: 2007
Location: Sydney, Australia.
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: Multiple form fields to one database column
Share on: 
fb share twitter share gplus share more share

Can you post the code from your initial form?

The input filed names should be something like name="customer_comment[]"

Also, I hope you are checking the return values for html and other injection hacks otherwise you will be in real trouble...
MarkLL is offline  
The Following User Says Thank You to MarkLL For This Useful Post:
Unread 8th Oct 2012, 10:45 AM   #3
TNT
 
otfromtot's Avatar
 
Join Date: 2012
Location: florida
Posts: 65
Thanks: 19
Thanked 5 Times in 5 Posts
Default
Re: Multiple form fields to one database column
Share on: 
fb share twitter share gplus share more share

the issue ended up being in the submission page that the form was linked to. I used this javascript instead.

<div class="fieldContainer">

<p> Beam Size:<input type="text" name="beam" id="beam" onKeyUp="return bar()" /></div>
<p>
<div class="fieldContainer">
<select name="beamm" id="beamm" onChange="return bar()"><option label="Select one">Feet/Meters</option><option label="feet" value="feet">Feet</option><option label="meter">Meters</option></select>
</p>
</p>
</div>
<div class="fieldContainer">
<p> Mast Height:<input type="text" name="mast" id="mast" onKeyUp="return bar()"/></p></div>
<div class="fieldContainer"><p><select name="mastm" id="mastm" onChange="return bar()"><option label="Select one">Feet/Meters</option><option label="feet" value="feet">Feet</option><option label="meter">Meters</option></select>
</p>
</div>
<div class="fieldContainer">
<p> Towable Trailer:<select name="trailer" id="trailer" onChange="return bar()"><option label="Select one">Select one</option><option label="Yes" value="yes">Yes</option><option label="No" value="0">No</option><option label="Not Suitable" value="no">Not Suitable</option></select>
</p>
</div>
<div class="fieldContainer">
<p>Overall Length:<input type="text" name="length" id="length" onKeyUp="return bar()" /></p></div>
<div class="fieldContainer"><select name="lengthm" id="lengthm" onChange="return bar()"><option label="Select one">Feet/Meters</option><option label="feet" value="feet">Feet</option><option label="meter">Meters</option></select>
<br />
</p>
</div>
<div class="fieldContainer">
<p>Overall Height:<input type="text" name="height" id="height" onKeyUp="return bar()" /></p></div>
<div class="fieldContainer"><select name="heightm" id="heightm" onChange="return bar()"><option label="Select one">Feet/Meters</option><option label="feet" value="feet">Feet</option><option label="meter">Meters</option></select>
<br />
</p>
</div>
<div class="fieldContainer">
<p>Category:<select name="category" id="category" onChange="return bar()"><option label="Select one">Select one</option><option label="Power" value="power">Power</option><option label="Sail" value="sail">Sail</option></select>
<br />
<textarea id="customer_comment" name="customer_comment" style="visibility:hidden"></textarea>
</p>
</div>

<script language="javascript" type="text/javascript">

function bar()
{

document.getElementById('customer_comment').value =
" beam: " + document.getElementById('beam').value + "" +
" " + document.getElementById('beamm').value + "|" +
" mast: " + document.getElementById('mast').value + "" +
" " + document.getElementById('mastm').value + "|" +
" trailer: " + document.getElementById('trailer').value + "|" +
" length: " + document.getElementById('length').value + "" +
" " + document.getElementById('lengthm').value + "|" +
" height: " + document.getElementById('height').value + "" +
" " + document.getElementById('heightm').value + "|"
" category: " + document.getElementById('category').value + "|";
}



</script>
otfromtot is offline  
Unread 9th Oct 2012, 01:16 AM   #4
Software Product Creator
War Room Member
 
SteveSRS's Avatar
 
Join Date: 2012
Location: NL => Thailand
Posts: 452
Thanks: 42
Thanked 164 Times in 93 Posts
Blog Entries: 5
Default
Re: Multiple form fields to one database column
Share on: 
fb share twitter share gplus share more share

this would have been the change to make it work probably:

foreach($_POST['customer_comment'] as $value)
to
foreach($_POST['customer_comment'] as $key => $value)

SteveSRS is offline  
The Following User Says Thank You to SteveSRS For This Useful Post:
Unread 9th Oct 2012, 10:22 AM   #5
HyperActive Warrior
 
Join Date: 2012
Posts: 153
Thanks: 1
Thanked 7 Times in 7 Posts
Default
Re: Multiple form fields to one database column
Share on: 
fb share twitter share gplus share more share

Well An easy way to this is, just take all the comments in different variables like :
$comment1 = $_POST['comment1'];
$comment2 = $_POST['comment2'];
$comment3 = $_POST['comment3'];

and then join all of them under one variable
$finalcomment = $comment1.$comment2.$comment3;

All you need to do is post this variable into your table and you're done
boilingstocks is offline  
The Following User Says Thank You to boilingstocks For This Useful Post:
Closed Thread


Bookmarks

Tags
column, database, fields, form, multiple


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




All times are GMT -6. The time now is 10:30 AM.