homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Php array help
array from html form to php to mysql

Msg#: 4507837 posted 10:55 pm on Oct 13, 2012 (gmt 0)

Ok I need some help guys. I need to take an array from an html form into php, and then have it inserted in mysql. I am successfully getting the array from the form to the php part, but I am failing at inserting it into mysql. I will put an example of my code below. The form idea below is dynamically generated and there could be 1 entry or 100 entries that could be generated, but it will always get the name="title_1[]" attribute. I need it to insert all the entries that are there into a new database row. I'm not even sure if this is possible but if more clarification is needed just let me know.

The Form Idea:

<form action="index.php" method="post" data-ajax="false">
<div data-role="fieldcontain" style="border:0;">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Title 1:</legend>
<input type="radio" name="title_1[]" id="title_1" value="1" />
<label for="title_1">Ok</label>
<input type="radio" name="title_1[]" id="title_2" value="0" />
<label for="title_2">Not Ok</label>

The Php:

$grab_title = $_POST['title_1'];
$arr = array($grab_title);
echo implode(",",$arr);

The Php to MySQL:
I have failed with multiple ideas here any help?



WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4507837 posted 6:37 am on Oct 14, 2012 (gmt 0)

Show what you tried, so people can at least see that and offer fixes.

It might only be a small syntax error - or a complete misunderstanding.


Msg#: 4507837 posted 3:01 pm on Oct 14, 2012 (gmt 0)

double post

[edited by: whitecoder at 3:35 pm (utc) on Oct 14, 2012]


Msg#: 4507837 posted 3:02 pm on Oct 14, 2012 (gmt 0)

Here's something I tried, I am aware of the security issues with what is sitting here that will be taken care of after I fix this issue.

$grab_title = $_POST['title_1'];

foreach($grab_title as $key => $val){
mysql_query("INSERT INTO vehicle_inspection (selection) VALUES ($val)");


Msg#: 4507837 posted 1:59 am on Oct 17, 2012 (gmt 0)

For anybody else that may have this problem here is my php solution.

$fix = $_POST['help'];
$fix2 = $_POST['text_a'];

$chelp = count($fix);
$ctext = count($fix2);
if($chelp == $ctext)
for($x = 0; $x < $chelp; $x++)
$str[] = "('{$fix[$x]}','{$fix2[$x]}')";
$s = implode(',',$str);

mysql_query ("INSERT INTO vehicle_inspection (selection,problem) VALUES $s");

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved