Jump to content

INSERT INTO and CONNECTION with an array.


RCS

Recommended Posts

ok if I want to use the script below how would I INSERT array info into a database

 

Thanks in advance

 

<?php
$imagedir = "x";
if (isset($_POST['btnSub']))
{
    $desc = $_POST['desc'];
    $price = $_POST['price'];
    $make = $_POST['make'];
    
    foreach ($_FILES['picfile']['name'] as $k => $name)
    {
        
        $tmpname = $_FILES['picfile']['tmp_name'][$k];
        $type = $_FILES['picfile']['type'][$k];
        
        // process each pic here
    }
    
    // update db here
}


?>

<form method='post' enctype='multipart/form-data'>

<?php


    echo "Make <input type='text' name='make[]' /><br/>";
    echo "Description  <input type='text' name='desc[]' size='60' /><br/>";
    echo "Price  <input type='text' name='price[]' /><br/>";
    for ($i=1; $i<=10; $i++)
    {
        echo "<fieldset>\n";
        echo "<legend>Picture $i</legend>\n";
        echo "<input type='file' name='picfile[]' size='60' /><br/>";
        echo "</fieldset><br/>\n";
    }
?>
<input type='submit' name='btnSub' value='Submit'>
</form>

 

 

Then tried something like this to connect and INSERT but it did not work.

 

 $query = "INSERT INTO upload(id, name, TYPE, size, content, make, description, price,  name2, type2, size2, content2, name3, type3, size3, content3, name4, type4, size4, content4, name5, type5, size5, content5, name6, type6, size6, content6, name7, type7, size7, content7, name8, type8, size8, content8, name9, type9, size9, content9, name10, type10, size10, content10,)".
"VALUES ($_POST[id],'$fileName', '$fileType', '$fileSize', '$content','$_POST[make]','$_POST[description]','$_POST[price]','$fileName2', '$fileType2', '$fileSize2', '$content2', '$fileName3', '$fileType3', '$fileSize3', '$content3', '$fileName4', '$fileType4', '$fileSize4', '$content4', '$fileName5', '$fileType5', '$fileSize5', '$content5', '$fileName6', '$fileType6', '$fileSize6', '$content6', '$fileName7', '$fileType7', '$fileSize7', '$content7', '$fileName8', '$fileType8', '$fileSize8', '$content8', '$fileName9', '$fileType9', '$fileSize9', '$content9', '$fileName10', '$fileType10', '$fileSize10', '$content10',)";  

 

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.