I am trying to generate some xml with this php code here… I am trying to use this script for an ios app I am learning from as I go just to figure out how each of the parts fit i.e. (app, php, mysql, xml)
Here is my php script that my ios app is exicuting
<?php
header("Content-type: text/xml");
$username="*****";
$password="***";
$database=" *****";
$testcode=$_REQUEST['usercode']; ////testcode coming from ios app
//connect to database
$connect = mysql_connect('localhost',$username,$password) or die('No DB Connection');
//select database
$db = mysql_select_db('N_codes', $connect) or die("<b>Unable to select specified database</b>");
//Do some stuff here
$query = "SELECT codes FROM codes where id = '$testcode'"; //testcode coming from ios app
$result = mysql_query($query,$connect);
//XML STUFF
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
$row = mysql_fetch_assoc($result);
$xml_output .= "\t\t<code>" . $row['codes'] . "</code>\n";
$xml_output .= "</entries>";
echo $xml_output;
?>
This is all that it is producing
<?xml version="1.0"?>
<entries>
<code></code>
</entries>
What I am looking for is a code that should be between that is in the mysql database and is found by the user supplying a code that is passed to the php script.
Can anyone see whats missing?
I see a few "potential" problems with the code you provided above.
1. Is your table named
codesand the field you’re looking for alsocodes? Your SQL question is looking for a field name codes in a table called codes. It’s hard to tell whether or not that’s a problem but must rows represent a single field so the plural version of the word "code" makes me believe you made a mistake there.2. Try adding a
dieafter the query that outputs [mysql_error][2]just in case an error occurred.3. You should use
mysql_real_escape_stringwhen you use user supplied data in a SQL query.