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 7503225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:08:48+00:00 2026-05-29T21:08:48+00:00

I want to merge data into a MySQL table from PHP : <?php function

  • 0

I want to merge data into a MySQL table from PHP :

<?php
function convertFromDateHM($str)
{
    $tmp=$str;
    $Y=substr($tmp, 6,4); 
    $M=substr($tmp, 3,2); 
    $D=substr($tmp, 0,2);
    $H=substr($tmp, 13,2);
    $MN=substr($tmp, 18,2);
    $tmp=$Y.'-'.$M.'-'.$D.' '.$H.':'.$MN.':00';
    return $tmp;
}
function mergeCompteRendu($compterendu)
    {
        $resultat=explode("\n",$compterendu);
        $connec = mysql_connect("192.168.1.123:3306","root", "mysqlroot");
        mysql_set_charset('utf8', $connec);
        mysql_select_db("finance",$connec);
        for($i = 0; $i < count($resultat) ; $i++)
        {
            $valeur=explode(";",$resultat[$i]);
            if ($valeur[0] != '0')  // case of update
            {
                $requete = mysql_query("UPDATE compte_rendu SET  
                cr_date    = '".convertFromDateHM($valeur[1])."',
                cr_lieu    = '".$valeur[2]."',
                cred_id    = '".$valeur[3]."',
                cr_resultat = '".$valeur[5]."',
                cr_comment = '".$valeur[6]."',
                adc_id = '".$valeur[7]."' 
                WHERE cr_id = '".$valeur[0]."'");  // cr_id is the primary key which is auto_increment
            }
            else   // case of insert : here is the problem raised
            {
                $requete = mysql_query("INSERT INTO compte_rendu(cr_date,cr_lieu,cred_id,cr_resultat,cr_comment,adc_id) SET 
                                        cr_date    = '".convertFromDateHM($valeur[1])."',
                                        cr_lieu    = '".$valeur[2]."',
                                        cred_id    = '".$valeur[3]."',
                                        cr_resultat = '".$valeur[5]."',
                                        cr_comment = '".$valeur[6]."',
                                        adc_id = '".$valeur[7]."' ");
            }
        }
        return $resultat[0];
    }

NB : the “cr_date” column is of datatype datetime.

This PHP is a webservice which I call from a J2ME client. When I run the app then the record is not inserted into the database ( I checked it through SQLYog ). It’s the case of insert which causes problem , the update is ok.

So what is wrong in my code ?

  • 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-05-29T21:08:52+00:00Added an answer on May 29, 2026 at 9:08 pm

    Your insert query syntax in the code is wrong. You should be using either of the following form.

    INSERT into TABLE_NAME SET column_name1='value1',column_name2='value2'
    

    or,

    INSERT into TABLE_NAME (column_name1,column_name2) VALUES('value1','value2')
    

    But in your code you have mixed up the insert syntax so it is not working. You can use die(mysql_error()) to see the exact error generated by MySQL.

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

Sidebar

Related Questions

I want to merge data. Following are my MySQL tables. I want to use
I'm using a stored procedure to update\insert data into a table using MERGE. One
I want to merge multiple rss feeds into a single feed, removing any duplicates.
Let's say that I want to merge from a release branch to the master
I have two mysql tables and i want to merge the results of these
I am trying to merge records from an Oracle database table to my local
I have two data frames, Data1 and Data2, that I want to merge based
I want to push all data from SourceTable to TargetTable by inserting or updating
I want to make a program that concatenates an exe and data into one
In django, I want to copy data from identical tables in one db to

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.