Jump to content

Posting array values in MySQL


buchberg

Recommended Posts

Apache/2.2.21 (Win32) PHP/5.3.5

 

I've tried this for awhile, and it is killing me.  Any help would be appreciated.  All I want to do is take checkbox input (from a form), sent to to the server side (?????). 

 

Everything is on a local machine.  Im a noob, so be nice please.  I'm posting to MySQL, but the value shows the word (Array).  I'm having trouble with the 'foreach' function of an array.  Any help is appreciated.  I have (3) of these arrays.  If I can get one, the rest should be the same format.

 

 

$bid_status = $_POST['bid_status'];

var_dump($bid_status);

 

foreach ($_POST['bid_status'] =>$v_bs

 

??????? No idea.  I want to post the array value into the below sql 'INSERT into $table_name.....

 

(bid_status) would be my column name for the database-it is there and connecting.

However, VALUES ($_POST['bid_status']) posts the word (Array).  I want the checkbox values.  There are

4 of them similar to below.  Thank you in advance, and have a good day....

 

<INPUT TYPE=\"checkbox\" NAME=\"bid_status[]\" Value=\"spec\"><small><small>CMS</small></small>

 

$db_name="projects_bid_dates";

$table_name="project_status";

$connection=mysql_connect("localhost", "user", "password") or die (mysql_error());

$db=mysql_select_db($db_name, $connection) or die (mysql_error());

 

 

//line 34

$sql="INSERT INTO $table_name

(project_name, bid_date, bid_status, engineer, contractor, equipment, comments) VALUES

('$_POST[project_name]','$_POST[bid_date]', '$_POST[bid_status]','$_POST[engineer]', '$_POST[contractor]', '$_POST[equipment]', '$_POST[comments]')";

$result=mysql_query($sql, $connection) or die (mysql_error());

Link to comment
Share on other sites

Typically rather than imploding an array's values and storing it in one row, you would have a new row for each value, and link them back to the parent row with an ID.

 

You also have the foreach() syntax wrong in your example.

foreach($array AS $key=>$value){}

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.