Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving multiple filename (img_path) in one row separating with commas or |
    text
    copied!<p>The code I have worked except, it's only saving the first filename in the database. I want to be able to save them under <strong>img_path</strong> in one row separated by commas or | ---></p> <pre><code> img1.jpg, img2.jpg, img3.jpg </code></pre> <p>or </p> <pre><code> img123.jpg|img456.jpg|img789.jpg </code></pre> <p>Form:</p> <pre><code>&lt;input type="file" name="img[]" multiple="" /&gt; </code></pre> <p>Here's the full code</p> <pre><code> &lt;?php $con = mysql_connect( 'localhost', '', '') or die('Could not connect to mysql server.' ); mysql_select_db('shop', $con) or die('Could not select database.'); $product=mysql_real_escape_string($_POST['product']); $description=mysql_real_escape_string($_POST['description']); $category=mysql_real_escape_string($_POST['category']); $color=mysql_real_escape_string($_POST['color']); $sizes=mysql_real_escape_string($_POST['sizes']); $style=mysql_real_escape_string($_POST['style']); $material=mysql_real_escape_string($_POST['material']); $stock=mysql_real_escape_string($_POST['stock']); $ws_price=mysql_real_escape_string($_POST['ws_price']); $rt_price=mysql_real_escape_string($_POST['rt_price']); $sp_code=mysql_real_escape_string($_POST['sp_code']); foreach ($_FILES["img"]["error"] as $key =&gt; $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name =$_FILES["img"]["tmp_name"][$key]; //$tmp_name = implode(",", $_FILES["img"]["tmp_name"][$key]); $name = $_FILES["img"]["name"][$key]; $rand = rand(0000,9999); $px = $rand . $name; $px = preg_replace('/\s+/','_', $px); $px = str_replace('&amp;', 'and', $px); $target = 'img/'.$category.'/'; if (is_dir($target) == false) { mkdir($target, 0755); echo "Directory Created&lt;/br&gt;"; } $u = $target . $px; move_uploaded_file($tmp_name, $u); echo "". $px.", "; $a = array($px); $x = implode("|", $a); } } $sql = "INSERT INTO items ( product, description, category, color, sizes, style, material, stock, ws_price, rt_price, sp_code, img_path )VALUES( '$product', '$description', '$category','$color','$sizes','$style','$material','$stock','$ws_price','$rt_price','$sp_code','$x' )"; $result = mysql_query($sql); if($result){ echo("&lt;br&gt;Product Added!"); } else{ echo("&lt;br&gt;Failed! Please try again.");} mysql_close($con); ?&gt; </code></pre> <p>I've used this </p> <pre><code>$x = implode(',', $px) $sql = "INSERT INTO items (img_path)VALUES('$x');"; </code></pre> <p>and this</p> <pre><code>$sql = "INSERT INTO items (img_path)VALUES('". implode(',', $px)."')"; </code></pre> <p>it would always give me an error.</p> <pre><code> Warning: implode(): Invalid arguments passed in [...] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload