| Php array help array from html form to php to mysql |
whitecoder

msg:4507839 | 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> </fieldset> </div> </form>
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?
|
g1smd

msg:4507881 | 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.
|
whitecoder

msg:4507956 | 3:01 pm on Oct 14, 2012 (gmt 0) | double post [edited by: whitecoder at 3:35 pm (utc) on Oct 14, 2012]
|
whitecoder

msg:4507957 | 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)"); }
|
whitecoder

msg:4508713 | 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"); }
|
|
|