Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:17:17+00:00 2026-06-08T21:17:17+00:00

i try to insert multiple row in my database, that image not save to

  • 0

i try to insert multiple row in my database, that image not save to folder and
i get this error

Blockquote ArrayArrayYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Chrysanthemum.jpg’), (‘Hydrangeas.jpg’)’, ‘(‘Chrysanthemum.jpg’), (‘Hydrangeas.j’ at line 1

this is my code :

$hopid = $_POST[photo_hop_id];
$title = $_POST['photo_name_id'];

if(!is_array($title)) {
    $title = array();
}

$titleds = "('" . implode("'), ('", $title) . "')";

$tmp_file = $_FILES['ne_photo_image']['tmp_name'];
$file = $_FILES['ne_photo_image']['name'];  

if(!is_array($tmp_file)) {
    $tmp_file = array();
}
if(!is_array($file)) {
    $file = array();
}

$sementara = "('" . implode("'), ('", $tmp_file) . "')";
$filed = "('" . implode("'), ('", $file) . "')";    

$tmp_file1 = $_FILES['fe_photo_image']['tmp_name'];
$file1 = $_FILES['fe_photo_image']['name']; 

if(!is_array($tmp_file1)) {
    $tmp_file = array();
}
if(!is_array($file1)) {
    $file = array();
}

$sementara1 = "('" . implode("'), ('", $tmp_file) . "')";
$filed1 = "('" . implode("'), ('", $file) . "')";   

if(!move_uploaded_file($sementara, 'image/' . $filed)) {
    echo $_FILES["ne_photo_image"]["error"];
}

if(!move_uploaded_file($sementara1, 'image/' . $filed1)) {
    echo $_FILES["fe_photo_image"]["error"];
}

$y = "INSERT INTO photo VALUES (null, '".$filed."', '".$filed1."', '".$hopid."', '".$titleds."')";
$z = mysql_query($y) or die (mysql_error());
if($z) {
    $msg = "Data sudah ditambahkan";
}
else {
    $msg = "Data tidak bisa dimasukkan";
}

echo print_r($y);

and this is my form:

<form method="post" enctype="multipart/form-data">
    <table border="0"cellpadding="0" cellspacing="0" width= "100%">
        <tr>
            <td>Hop Name :<?echo "$data[hop_name]"?>
                <input type='hidden' name='photo_hop_id' value='<?echo"$data[hop_id]"?>'>
            </td>
        </tr>
        <table border="0"cellpadding="0" cellspacing="0" width= "100%">
            <tr>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    Near End Site Name : <?echo "$data[ne_site_name]" ?>
                    </br>
                    Near End Site Id : <?echo "$data[ne_site_code]" ?>
                </td>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    Far End Site Name : <?echo "$data[fe_site_name]" ?>
                    </br>
                    Far End Site Id : <?echo "$data[fe_site_code]"?>
                </td>
            </tr>   
            <tr>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    <?  $pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 1");
                    $dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]" ?> 
                    <input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :  
                    <input type="file" name="ne_photo_image[]">
                </td>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    <?echo "$dpm1[0]"?> : <input type="file" name="fe_photo_image[]">
                </td>
            </tr>   
            <tr>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    <? $pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 2");
                    $dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]" ?> 
                    <input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :  
                    <input type="file" name="ne_photo_image[]">
                </td>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    <?echo "$dpm1[0]"?> : <input type="file" name="fe_photo_image[]">
                </td>
            </tr>   
        </table>
    </table>

    <input type="submit" value="insert" />
</form>

many thanks for help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:17:18+00:00Added an answer on June 8, 2026 at 9:17 pm

    Your error comes clearly from this line :

    $y = "INSERT INTO photo VALUES (null, '".$filed."', '".$filed1."', '".$hopid."', '".$titleds."')";
    

    For example, your var $filed is an imploded array, which looks like ('foo'), ('bar'). Finally, your request will looks like INSERT INTO photo VALUE (null, '('foo'), ('bar')', [...]);.

    You must escape simple quotes in $filed, $filed1, $hopid, $titleds, but I’m pretty sure your request is totally wrong.

    Can you give us the photo table schema structure please ?

    EDIT :

    structure given : (photo_id,ne_photo_image,fe_photo_image,hop_id,title)

    To insert multiple rows in a table, you must use this kind of syntax :

    INSERT INTO photo(`photo_id`, `ne_photo_image`, `fe_photo_image`, `hop_id`, `title`)
    VALUES
        (null, 'foo', 'bar', 'baz', 'qux'),
        (null, 'foo', 'bar', 'baz', 'qux'),
        (null, 'foo', 'bar', 'baz', 'qux');
    

    Aka, you must insert your datas row by row, not column by column (what you’re trying to attempt right now).

    Your code should looks like this (this is definitely not a full piece of code, I’m not sure to understand all your code, then I give you some track) :

    <?php 
       $hopid = $_POST['photo_hop_id'];
    
       $titles = $_POST['photo_name_id'];
       $ne_photo_images = $_FILES['ne_photo_image']['tmp_name'];
       $fe_photo_images = $_FILES['fe_photo_image']['tmp_name'];
    
       /*
       I assume $titles, $ne_photo_images and $fe_photo_images 
       have the same number of elements, in the right order.
       */
    
       $sql = "INSERT INTO photo(`photo_id`, `ne_photo_image`, `fe_photo_image`, `hop_id`,    `title`) VALUES";
       for($i = 0, $l = sizeof($titles) ; $i < $l ; $i++)
       {
          //adding row datas
          $sql .= " (null, 
                     '".$ne_photo_images [$i]."', 
                     '".$fe_photo_images [$i]."', 
                     '".$hopid."', 
                     '".$titles[$i]."')";
          if($i < $l - 1)
             $sql .= ",";
       }
    
       if(mysql_query($sql))
          //get happy
       else
          //take a coffee
    ?>
    

    Again, this code is far from perfect, I’m just trying to explain you how to approach the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i try to insert the value from the textbox into the database, the
I am getting an error when I try to insert an item into a
If I try this statement: INSERT INTO TerminalEventChild (id,stringValue) VALUES (64,'version123|'); MySQL fail with
i when i try to save my entitie buzzmate i have this exception :
In MySQL you can insert multiple rows like this: INSERT INTO 'tablename' ('column1', 'column2')
I know that I can insert multiple rows using a single statement, if I
So we have multiple stored procs that get used during a morning SQL job
I have a form that allows users to insert items in a database. A
I try to save a m2m relation of a model. This ends up in
i have a sqlite3 database that has multiple (six) tables and i need it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.