XML & String concatenation

Hi guys, I’m new to the forum & I’m returning to PHP for the first time in several years; so I feel as if I’m a beginner again that will get back into the swing of things quickly. However, I have a question

I have the following

[code]<? 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, I can send that string to a DB or even view it in the browser; whatever I need to do…
However, the XML actually consists of 25 elements

So I’m trying to do something like this

[code]$query = “INSERT INTO table VALUES(”;
foreach($xml->vote as $vote)
$query .= $vote->teamID;
$query .= “,”;


$query = substr($query , 0 , -1);
$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

Thanks for the potential help…

What’s the resulting query that is failing?

I think the problem is that when you do an INSERT INTO table VALUES(X1, X2, X3, … Xn) query, it has to match the table EXACTLY.

So you must have an exact number of columns as you do values in your table, Otherwise you would need to use something like
INSERT INTO table (COL1, COL2, COL3, … COLn) VALUES(X1, X2, X3, … Xn)

Although, I think you might need to hone it down even more to specific individual queries. Perhaps a single query for EACH $vote?

Well, I’m not sure exactly what part is failing.

I’m passing a string from Adobe Flex to PHP and am trying to parse the XML. I have a table called votes; where I’m trying to have a table called votes with 26 columns; the first being the Primary Key which auto imcrements and the next 25 columns being the actual votes which are numerical ids to teams in the data base…

Does the outputted query exactly match the database. Did you verify it? If you echo out the query and manually enter into your DB does it work?

Are you getting errors? ;) Use error_reporting(E_ALL).

Sponsor our Newsletter | Privacy Policy | Terms of Service