php - generating XML from mysql server for iphone app consumption not working -


i trying generate xml php code here... trying use script ios app learning go figure out how each of parts fit i.e. (app, php, mysql, xml)

here php script ios app exicuting

<?php  header("content-type: text/xml");   $username="*****"; $password="***"; $database=" *****";  $testcode=$_request['usercode']; ////testcode coming ios app  //connect 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 select specified database</b>");   //do stuff here $query = "select codes codes id = '$testcode'"; //testcode coming 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 producing

<?xml version="1.0"?> <entries>         <code></code> </entries> 

what looking code should between in mysql database , found user supplying code passed php script.

can see whats missing?

i see few "potential" problems code provided above.

1. table named codes , field you're looking codes? sql question looking field name codes in table called codes. it's hard tell whether or not that's problem must rows represent single field plural version of word "code" makes me believe made mistake there.

$query = "select code codes id = '$testcode'"; 

2. try adding die after query outputs [mysql_error][2] in case error occurred.

$result = mysql_query($query, $connect) or die(mysql_error($connect)); 

3. should use mysql_real_escape_string when use user supplied data in sql query.

$testcode = mysql_real_escape_string($_request['usercode'], $connect); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -