user1434156
user1434156

Reputation:

Php storing url image path in MySQL DB

I am trying to store URL Image paths into MySQL DB. But i am not getting any results with my code.

Table Name: urlimage

id: autoincrement
image_name 



Php code for inserting data into DB
<?php

$images = explode(',', $_GET['i']);

$path = Configuration::getUploadUrlPath('medium', 'target');


if(is_array($images)){

    $objDb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
    $objDb->exec('SET CHARACTER SET utf8');

    $sql = "INSERT INTO `urlImage` (`image_name`) VALUES ";

  foreach ($images as $image) {

    //echo '<div><p>' . $path . $image . '</p><img src="' . $path . $image . '" /></div>';
    $value[] = "(".$path.$image.")"; // collect imagenames
  }

  $sql .= implode(',', $value).";"; //build query

  $objDb->query($sql);   
}

?>

Upvotes: 0

Views: 1283

Answers (2)

Krishna
Krishna

Reputation: 353

Try this; it may work:

$value[] = "('".$path.$image."')";

Upvotes: 2

xkeshav
xkeshav

Reputation: 54022

you have error in $sql

it must be $value[] = "('".$path.$image."')";

debug with

 echo "<pre>"; print_r($sql);echo "</pre>";

and if your using PDO function then call

prepare->execute

Upvotes: 0

Related Questions