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

  • Home
  • SEARCH
  • 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 6806169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:40:39+00:00 2026-05-26T19:40:39+00:00

I have this xml that I want to insert some info, the code is

  • 0

I have this xml that I want to insert some info, the code is working fine but when it comes to the address of the XML I’m having some trouble.

I have a link in other page with:

produtoadicionado.php?page=adicionar&cod_produto=1&id=1&nome_produto=Arroz

What I want is complete the name of the XML with the value of $id before. Which in this case is 1.

So it will call and add in: 1_produtos.xml

But is not working. Is creating a new xml named $id_produtos.xml

produtoadicionado.php

<?php 
$page = $_GET["page"];
$cod_produto = $_GET["cod_produto"];
$id = $_GET["id"];
$nome = $_GET["nome_produto"];



    if ($page == 'adicionar')
    {
    $xml = simplexml_load_file('$id_produtos.xml');
    $produto = $xml->addChild('produto');
    $produto->addChild('nome', $nome);
    $produto->addChild('cod', $cod_produto);
    file_put_contents('$id_produtos.xml', $xml->asXML());
}

?>

Please help me!

  • 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-26T19:40:39+00:00Added an answer on May 26, 2026 at 7:40 pm

    Change these lines:

    simplexml_load_file('$id_produtos.xml');
    file_put_contents('$id_produtos.xml', $xml->asXML());
    

    into this:

    simplexml_load_file("{$id}_produtos.xml");
    file_put_contents("{$id}_produtos.xml", $xml->asXML());
    

    Please, note the use of double quote instead of the single quote which let PHP to interpret the vars name and replace that with their value. You can read more here.

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

Sidebar

Related Questions

What I want to do is this: I have a pom.xml that depends on
I have a function that loads in some XML that looks like this: private
I have an XML file I want to insert that in a Datatable. The
I have XML that looks something like this: <Root xmlns=http://widgetspecA.com/ns> ...any... <WidgetBox> <A/> <B/>
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have an xml that looks like this: <Config> <A></A> <Template><B/><C/></Template> </Config> and I
I have an XML that goes like this: <?xml version=1.0 encoding=utf-8 ?> <colors> <color
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have a bunch of XML that has lines that look like this <_char

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.