Jump to content

turnin

Members
  • Posts

    11
  • Joined

  • Last visited

Everything posted by turnin

  1. Requinix, Got it parsing nicely, thanks heaps for helping, appreciated
  2. <?php $handle = curl_init(); curl_setopt($handle, CURLOPT_URL, '[url=https://infoconnect1.highwayinfo.govt.nz/ic/jbi/TrafficConditions2/REST/FeedService/]https://infoconnect1.highwayinfo.govt.nz/ic/jbi/TrafficConditions2/REST/FeedService/[/url]'); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($handle, CURLOPT_HTTPHEADER, array ('username:xxxx' , 'password: xxxx')); $response = curl_exec($handle); curl_close($handle); $xml = new SimpleXML($response); $motorway=$xml -> 'tns:motorways' //print_r($response); print_r($motorway); ?>
  3. Currently I just have code that calls the api with curl.this echos the return. I tried xmlsimple and it returned an empty array. Not too sure where to start or even if im going the right way about doing it.
  4. OK, I admit I'm a total newbie but been reading all day and making no progress in understanding. I have a script that calls an api, that api returns xml, like so https://dl.dropbox.com/u/40331447/samplereturn.xml I've tried SimpleXML and it fails as the return contains namespaces, I think. I will run this script once per hour for eg: I want to be able to send this to my mysql database and I'll eventually I'll query it based on the location fields What would be the easiest php method or library to parse this, so that each database entry is stored like so: ( from Parent_<tns:motorways> tns:name), (fromchild <tns:Locations> <tns:name>, <tns:congestion>, <Tns:direction>,<tns:lat>,<tns:lng> etc So the parent is in each entry along with each iteration of the children. Hope that makes sence , any help is really appreciated ! Cheers James.
  5. hmmm, OK, I've had a brief read, I assume I need to turn off magic quotes ? How can I achieve this ? Thanks for all the help so far
  6. A JSON array text must start with '[' at character 1 of You have an error in your SQL syntax; check the manual..................syntax to use near '\'driver\') at line 1 this came from sending randomkey||||||INSERT INTO table4 (`geolat;` , `geolong;` , `mode;`) VALUES (0.0,0.0,'driver')
  7. key||||||INSERT INTO table4 (`geolat;` , `geolong;` , `mode;`) VALUES (0.0, 0.0, "passenger") I know when I use INSERT INTO with just geolat and geolong I have success, as soon as I put mode; in there , it fails. Not sure how to use mysql_error() just yet, does this go into the index.php script ?
  8. ok, yes, thanks Kickstart. I can now insert, but only fields with numeric values, as soon as I insert to a text or varchar field I get errors. but again, I don't get the error if I go through the myphpadmin interface. I've tried using single , double and no quotes and I'm changing the data types field by field, still nothing. why would it be different using the phpmyadmin interface, The only thing I'm doing is deleting is is the "key|||||" part before the actual statement
  9. My version phpadmin is ver 3.3.1 Don't know how to find the mysql version number ?
  10. Okay, I'm hoping one of you can help me. I have a mysql database that I have configured through phpmyadmin. I have an android app that simply makes and sends a mysql query I can get it to successfully return values when using Select statements but when I use INSERT INTO, it returns " Error Query is invalid" BUT BUT BUT, when I use the same string and enter it through the sql tab in myphpadmin it works fine ! So here is the string ( the semicolons at the end of each field name are so I can use something common to split the string up when the data arrives back on the phone) randomkey||||||INSERT INTO table4 (`geolat;` , `geolong;` , `mode;` , `destgeolat;` , `destgeolong;` , `cellphone;` , `email;` , `carrego;` , `colour;` , `rating;` , `comment;`) VALUES (0.0,0.0,'driver' ,-43.54779,172.62472, , '' ,'' , 'text' , 'ratingleftblank' , 'commentblank' ) the index4.php script is as follows ?php /* * Written By: * James */ /************************************CONFIG****************************************/ //DATABSE DETAILS// $DB_ADDRESS="mysql1.openhost.net.nz"; $DB_USER="bling44"; $DB_PASS="sadlyinept"; $DB_NAME="bling44"; //SETTINGS// //This code is something you set in the APP so random people cant use it. $SQLKEY="randomkey"; /************************************CONFIG****************************************/ //these are just in case setting headers forcing it to always expire and the content type to JSON header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); if(isset($_POST['tag'])){ //checks ifthe tag post is there $tag=$_POST['tag']; $data=explode("||||||",$tag); //split the SQL statement from the SQLKEY if($data[0]==$SQLKEY){ ///validate the SQL key $query=$data[1]; $link = mysql_connect($DB_ADDRESS,$DB_USER,$DB_PASS); //connect ot the MYSQL database mysql_select_db($DB_NAME,$link); //connect to the right DB if($link){ $result=mysql_query($query); //runs the posted query (NO PROTECTION FROM INJECTION HERE) if($result){ if (strlen(stristr($query,"SELECT"))>0) { //tests if its a select statemnet $outputdata=array(); while ($row = mysql_fetch_assoc($result)){ $outputdata[]=$row; //formats the result set to a valid array } echo json_encode(array("VALUE",$tag,array_merge($outputdata))); //sends out a JSON result with merged output data } else { echo json_encode(array("VALUE",$tag,array_merge(array(array("AFFECTED_ROWS ".mysql_affected_rows($link)))))); //if the query is anything but a SELECT it will return the array event count } } else echo json_encode(array("VALUE",$tag,array_merge(array(array("ERROR QUERY IS INVALID"))))); //errors if the query is bad mysql_close($link); //close the DB } else echo json_encode(array("VALUE",$tag,array_merge(array(array("ERROR Database Connection Failed"))))); //reports a DB connection failure } else { echo json_encode(array("VALUE",$tag,array_merge(array(array("ERROR BAD CODE SUPPLIED"))))); //reports if the code is bad } } ?> So to reiterate. I can search the DB but can't INSERT INTO, unless I go through the myphpadmin interface. Any ideas are very much appreciated
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.