hamburgerlove413 Posted February 15, 2014 Share Posted February 15, 2014 Hello, I have an xml file that I then convert to json, and save it as a text file. What I'm trying to do is to then take this text and insert all of it into one field in a table. When I do, a record is added, but its blank, theres no data. I can add it through phpmyadmin, and i can change what I'm adding to a simple string and it gets added through php, but when I try to add the actual text it's not there. Anyone have any ideas what I'm doing wrong? I'm also getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't Remember To Forget You, Shakira Featuring Rihanna","link":"http:\/\/www1.billb' at line 1 (its Billboards Hot 100 rss feed) I don't even need it converted to Json, if thats simpler, I just need to save the contents of the XML into a table. my code to get and save the file: $billboardFile = "http://www1.billboard.com/rss/charts/hot-100"; $loadBillboard = simplexml_load_file($billboardFile); $loadBillboard->asXML("data/billboard.xml"); $url = 'data/billboard.xml'; $billboardLoad = file_get_contents($url); $billboardLoad = str_replace(array("\n", "\r", "\t"), '', $billboardLoad); $billboardLoad = trim(str_replace('"', "'", $billboardLoad)); $loadBB = simplexml_load_string($billboardLoad); $bbJson = json_encode($loadBB); $fileName = 'data/bbJson.txt'; if (file_exists($fileName)) { $lBillboard = file_get_contents($file); $lBillboard = $bbJson; file_put_contents($fileName, $lBillboard); } my main page: <!doctype html> <?php //include folder path $incPath = 'includes/'; include $incPath . 'getFile.php'; include $incPath . 'conn.php'; ?> <html> <head> <meta charset="utf-8"> <title>Assignment 01 AJAX – Nicholas Barna</title> </head> <body> <?php $dataBB = file_get_contents('data/bbJson.txt'); $query="INSERT INTO xmladd (id,text) VALUES (null,'$dataBB')"; $result=$mysqli->query($query) or die ($mysqli->error); ?> <div id="listings"></div> <!--<script type="text/javascript" src="js/javascript.js"></script>--> </body> </html> theres also a connection file, and then the xml and txt files. I'm attaching the txt file that it creates. bbJson.txt Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 15, 2014 Share Posted February 15, 2014 (edited) Any reason you're storing it both on the file system and the database? But to answer your question you need to apply mysql_real_escape_string to $dataBB before using it in your query. EDIT Just noticed you're using mysqli, use mysqli_real_escape_string instead. Edited February 15, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
hamburgerlove413 Posted February 15, 2014 Author Share Posted February 15, 2014 Thank you! That worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.