Using SimpleXML Element

This is a discussion on Using SimpleXML Element within the PHP Language forums, part of the PHP Programming Forums category; Hi guys, It's been a long while since I've used PHP so I'm a bit rusty, been ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-07-2008
bryan.kardisco@gmail.com
 
Posts: n/a
Default Using SimpleXML Element

Hi guys,

It's been a long while since I've used PHP so I'm a bit rusty, been a
C# monkey as of late - but on to the problem at hand.

I have the following

<? php

#Convert the String Into XML
$xml = new SimpleXMLElement($_POST['name']);

#Itterate through the XML for the data
foreach($xml->vote as $vote)
{
$foo .= $vote->teamID;
}

?>

And that does work it gets me all the values


But what I want to do is have something like

$query = "INSERT INTO table VALUES(";
foreach($xml->vote as $vote)
{
$query .= $vote->teamID;
$query .= ",";
}

$query = substr($query , 0 , -1);
$query .= ");";

mysqli->query($query);


But for some reason this just doesn't work; obviously I'm assuming
it's a syntax issue and I'm just an idiot; but some help would be
amazing
Reply With Quote
  #2 (permalink)  
Old 03-08-2008
bryan.kardisco@gmail.com
 
Posts: n/a
Default Re: Using SimpleXML Element

.... anyonoe?
Reply With Quote
  #3 (permalink)  
Old 03-08-2008
Luuk
 
Posts: n/a
Default Re: Using SimpleXML Element

bryan.kardisco@gmail.com schreef:
> Hi guys,
>
> It's been a long while since I've used PHP so I'm a bit rusty, been a
> C# monkey as of late - but on to the problem at hand.
>
> I have the following
>
> <? php
>
> #Convert the String Into XML
> $xml = new SimpleXMLElement($_POST['name']);
>
> #Itterate through the XML for the data
> foreach($xml->vote as $vote)
> {
> $foo .= $vote->teamID;
> }
>
> ?>
>
> And that does work it gets me all the values
>
>
> But what I want to do is have something like
>
> $query = "INSERT INTO table VALUES(";
> foreach($xml->vote as $vote)
> {
> $query .= $vote->teamID;
> $query .= ",";
> }
>
> $query = substr($query , 0 , -1);
> $query .= ");";
>
> mysqli->query($query);
>
>
> But for some reason this just doesn't work; obviously I'm assuming
> it's a syntax issue and I'm just an idiot; but some help would be
> amazing


try to print $query to your screen (or logfile) and try to put it
directly in the mysql-client, and check for errors you might get.

produce output of " echo $query ", and the error, than some-one might
help you...


--
Luuk
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:26 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0