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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:19:16+00:00 2026-06-15T17:19:16+00:00

Here is my most current code that is not sending any values to the

  • 0

Here is my most current code that is not sending any values to the database but doesnt report any errors.

 foreach($library->time_report as $project){
            mysql_query("INSERT INTO instancetable (project_ID,          project_status, client_ID, project_start_time, project_end_time, project_total_time, employee_ID, employee_name, date_created, date_modified, created_by, client_name, priority, organization, number_of_required_types) 
            VALUES ('{$project->project_ID}',{$project->project_status}, '{$project->client_ID}', {$project->project_start_time}, '{$project->project_end_time}', '{$project->project_total_time}','{$project->employee_ID}', {$project->employee_name}, {$project->date_created}, {$project->date_modified}, {$project->created_by}, {$project->client_name}, {$project->priority}, {$project->organization}, {$project->number_of_required_types}");

}

I need to upload an XML file into mysql. It says it is sucessfully uploading, but it just puts a value of 0 in the table. Heres my code:

<?php

     echo "starting <br><br>";
     //mysql connection
$con2 = mysql_connect("localhost","test","test");
if (!$con2)  {  die('Could not connect: ' . mysql_error());  }
$selectdb = mysql_select_db("test", $con2);
if (!$selectdb)  { die('Database not used: ; ' . mysql_error());  }

echo "connected to DB<br/><br/>";

 //simplexml load xml file   
$library =  simplexml_load_file('http://localhost/instance.xml');

echo "xml loaded<br/><br/>";

//loop through parsed xmlfeed and print output      

foreach ($library->message as $message) {                  
printf("project_ID: %s\n", $project_ID->project_ID);                  
}

echo "xml parsed<br/><br/>";

//insert into databse                     
mysql_query("INSERT INTO instancetable (project_ID)
VALUES ('project_ID')")
or die(mysql_error());

echo "inserted into mysql<br/><br/>";

//show updated records            
printf ("Records inserted: %d\n", mysql_affected_rows());  



//close connection 
mysql_close($con2);
echo " <br /> Finished "
?>

So this is the out put I get:

starting 

connected to DB

xml loaded

xml parsed

inserted into mysql

Records inserted: 1 
Finished

XML File:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project>
<time_report>
    <project_ID>4</project_ID>
    <project_status>Closed</project_status>
    <client_ID>6001</client_ID>
    <time_record>
        <project_start_time>13:03:19.000</project_start_time>
        <project_end_time>13:14:26.000</project_end_time>
        <project_total_time>0.0104166666666667</project_total_time>
    </time_record>
    <employee_ID>10001</employee_ID>
    <employee_name>Mary Beth</employee_name>
    <date_created>2009-07-02</date_created>
    <date_modified>2009-11-24</date_modified>
    <created_by>Mary Beth</created_by>
    <client_name>BlackRock Funds</client_name>
    <priority/>
    <organization/>
    <number_of_required_types>9999999999</number_of_required_types>
</time_report>

The XML file is shown above, it is much larger so I took just one entry out.

  • 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-15T17:19:17+00:00Added an answer on June 15, 2026 at 5:19 pm

    $project_ID is not set. The foreach loop probably runs but since $project_ID is not defined it doesn’t output anything.

    If you want to insert and print each project ID you need the insert query inside the foreach loop.

    foreach($library->time_report as $project){
      mysql_query("INSERT INTO instancetable (project_ID) 
        VALUES ('{$project->project_ID}')");
    
      printf("project_ID: %s\n", $project->project_ID);
    }
    

    Note that project_ID is being inserted as a string here. If the database field is an integer you should remove the single quotes surrounding $project->project_ID.

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

Sidebar

Related Questions

Here's a piece of code that takes most time in my program, according to
This is most likely not an easy one but here is the situation: I
This is probably a trivial question for most but here goes... I am using
I hope I'm not duplicating here :-) I'm wondering what's the most effective way
I've looked on here and most say that its escape problems so I think
Here is my code. I am not sure how to exit the program using
Ok, I have code that is working (posted after this) but before I expand
We have decided to work with the Insert Framework Here We'll most likely update
Here is a quick overview of the controllers functionality in most of the application:
Question about logics here: What's the most elegant way to make the menu appear/disappear

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.