Jump to content

[SOLVED] Trying to upload Array into a mySql db - trying is operative word


CincoPistolero

Recommended Posts

I've been trying to follow an online tutorial on how to load arrays into mulitple rows using checkboxes in a db. I am able my array created. I am able to pass some IDs to my confirmation page. But I can't get the code to actually enter it in the DB and I'm not getting any errors on my page.

 

On my confirmation page, I confirm that my POST is sending data, by:

 

echo "<pre>";
print_r($_POST);
echo "</pre>\n"

 

this results in:

 

 

Array

(

    [optPricesID] => Array

        (

            [0] => 35

            [1] => 37

            [2] => 39

        )

 

)

 

Below is the code I have that tries to take this array and put it into a db. I do have the connection php code to the database in place at the top of the page. Any and all help is appreciated.

 

$tsID=3;
function insert_skills($tsID, $optPricesID) {
   
   purge_lookup("testSpecsOpt", $tsID);
   
   $query = create_checkbox_query($optPricesID, "testSpecsOpt", $tsID);
   
   mysql_query($query);
}

function purge_lookup($table, $tsID) {
  $q = "DELETE FROM testSpecsOpt, WHERE testSpecsID = '$tsID'";
  mysql_query($q);
}

function create_checkbox_query($arr, $table, $tsID) {
   $q = "INSERT INTO testSpecsOpt (testSpecsID, optPricesID ) VALUES";

   foreach ($arr as $check) {
     $q .=  " ( $tsID , $check )" . ",";

   }
   
   return substr($q, 0, -1);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.