Jump to content

Inserting a text file into a mysql table


hamburgerlove413

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.