Jump to content

Murciano

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Murciano's Achievements

Member

Member (2/5)

0

Reputation

  1. HI, Im having an issue with a small piece of custom php code inside WP, heres a brief explanation of what im doing and below is the code. Im using a permalink structure of %category%/%postname% Basically im using simplehtml dom to grab some stocks info and write it to a text file, which it does when i use this code: include ('crawler_file.php'); $html = file_get_html("http://url that the info comes from/ticker=$Symbol:US"); $es = $html->find('div[class="detailsDataContainerLt"]'); $tickerdetails = ("$es[0]"); $CompDetails = "$Symbol.txt"; $FileHandle2 = fopen($CompDetails, 'w') or die("can't open file"); fwrite($FileHandle2, $tickerdetails); fclose($FileHandle2); however when i use that code above it gets the info ok but writes the file into WP root and not into the same folder from where called within the theme, strange thing is though the include file gets included no problem. I have tried absolute URL and also bloginfo each just throws out "or die" error of Cant Find File. Its obviously a paths issue but im stuck as what to do next thanks
  2. Thanks for the quick reply Zach, so i am on the right track, will have to look into things more deeply, it doesnt work however so what could be the problem with my $body, im calling the preg_replace right after this $body = file_get_contents('datafeed.txt', $body); could it be that?.. a couple of lines further down from my preg_replace i have a str_replace which works ok could there be some kind of clash?
  3. Im trying to get a preg_replace to work for editing dates in an txt file, all the dates are different and there are hundreds of them that have to be changed, i been reading up about preg_replace and came up with this line of code <?php $body = preg_replace("@<tDate>[0-9]/{4,5}</tDate>@", "<tDate>NEW DATE GOES HERE</tDate>", $body); ?> Its running ok (no errors,) but nothing is being updated in the txt file am i on the right path or going way off course with this line
  4. Thanks, i have been looking at the LOAD DATA INFILE query earlier today, but am a little stumped at how to code it, would i need to run 2 mysql queries?.. 1 with the version and id and the other with LOAD DATA or could i put it all in one query?, if it can be done in 1 query would this be right <?php mysql_query("INSERT INTO file id='$id', version='$version' LOAD DATA INFILE 'datafeed.txt' INTO TABLE file.xmlver "); $result = mysql_query($query); ?>
  5. I need to read from a file and insert the files content into a MySQL column the table contains 3 fields id INT version VAR xmlver LONGTEXT What im wanting to do is grab the file, read it and then write it to a txt file, then the data from the txt file be read and sent to MySQL along with the id and xmlver details, i have seen this code snippet but when i try it it doesnt get me anywhere (confuses me) mysql_query('insert into tablename (columnname) values ("' . mysql_real_escape_string(file_get_contents('somefile')) . '");'); Whats the best way to do this?, code below (is it worth writing the XML to txt before insertion or can i insert the xml as is?) <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <?php if (isset($_POST['version'])) { $version = $_POST['version']; $data = file_get_contents("datafeed.xml"); $data = file_put_contents('datafeed.txt', $data); file_put_contents('version.txt', $version); } ?> <p align="center"> <input type="text" name="version" value="<?php include("version.txt"); ?>"/> <input type="submit" name="<?php echo $version; ?>" value="Update Server" /> </p> </form>
  6. Well today managed to get somewhere at last (almost) this is the block of code now for the UPDATE query <?php // this part updates the database with the newly created business listing if (isset($_POST['submit'])) { $id= $_POST['id']; $location = $_POST['location']; $company_name = $_POST['company_name']; $editor1 = str_replace("\n\r","<br />",$_POST['editor1']); // lets populate the database with this new information $q = ("UPDATE listings SET location='$location', company_name='$company_name', editor1='$editor1' WHERE id='$id'"); $result = mysql_query($q) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); // success or failure ? if ($result) echo "<p align=\"center\"><u>The newly edited listing was successfully inserted into the Listing's database</u></p>"; else echo "<p align=\"center\"><font color=\"red\">There was a problem, the data got lost on the way.</font></p>"; } }else { /* Link back to main */ header("Location: index.php"); } ?> Now there are no errors, no updating all the rows in the table, just now it will not update its own row, i click submit, it returns success but the Db row has not been altered, no errors or anything to go on
  7. Ok Ken, thanks for all your help, i will look into what is causing it, once again many thanks.
  8. On clicking submit it shows this theres lots more about 1000 characters or so, but i guess the info you want is the first couple of lines
  9. Hi Ken, thanks for taking the time, using the complete block of code just returned a white page when refreshed, adding the mysql_real_escape_string into my code (same place as yours) returned the sam error with an extra slash example:"\\r\\n"
  10. This is the entire message what i have noticed is that the fatal error query seems to break just here during the update for the editor1 field
  11. Thanks for the heads up, i've added the id as you can see beneath the if(isset and also to the WHERE clause, now its giving me a fatal error of im looking at what the error says but it seems to be pointing at charset issues which isnt the case here (not that i am aware of anyway) if (isset($_POST['submit'])) { $id= $_POST['id']; $location = $_POST['location']; $company_name = $_POST['company_name']; $editor1 = $_POST['editor1']; // lets populate the database with this new information $q = ("UPDATE listings SET location='$location', company_name='$company_name', editor1='$editor1' WHERE $id='id'"); $result = mysql_query($q) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); // success or failure ? if ($result) echo "<p align=\"center\"><u>The newly edited listing was successfully inserted into the Listing's database</u></p>"; else echo "<p align=\"center\"><font color=\"red\">There was a problem, the data got lost on the way.</font></p>"; }
  12. This .php code fetche's data from MySQL and displays it in a texteditor (CKeditor) where it can be updated and returned to its same row, it fetches it ok, However after updating and clicking submit to return it to its row it just goes bananas and overwrites the whole table with the same content in each row, what do i need to add to the UPDATE query to get it to function properly? <?php // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. if(isset($select)&&$select!=""){ $select=$_GET['select']; } ?> <form id="form1" align="center" name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="select"> <option value="">Select Template For Editing</option> <?php // Get records from database (table "listings"). $q=mysql_query("SELECT * FROM listings ORDER BY id"); // Show records by while loop. while($row_list=mysql_fetch_assoc($q)){ ?> <p align="center"> <option value="<?php echo $row_list['id']; ?>"><?php echo $row_list['company_name']; ?></option> <?php // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <?php // If you have selected from list box. if(isset($select)&&$select!=""){ // Get records from database (table "name_list"). $result=mysql_query("SELECT * FROM listings WHERE id='$select'"); $row=mysql_fetch_assoc($result); ?> <div id="tempdetails">The listing that you have chosen to edit from is: <font color="red"><u><?php echo $row['company_name']; ?></u></font></div><!-- /tempdetails --> <p> <!-- ##### THIS FORM SHOWS (or should show) THE INFORMATION FROM EDITOR1 FIELD IN db ##### --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="test" method="post"> <p align="center"><font color="red">All fields are required.</font></p> <p align="center">Location: <input type="text" name="location" size="40" value="<?php echo $row['location']; ?>" /> Company Name: <input type="text" name="company_name" size="40" value="<?php echo $row['company_name']; ?>" /></p> <textarea id="editor1" name="editor1"><?php echo $row['editor1']; ?></textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor1', { enterMode : Number(2), filebrowserBrowseUrl : 'ckfinder/ckfinder.html', filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?type=Images', filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', } ); </script> </p> <p> <input type="submit" name="submit" /> </p> </form> <?php // End if statement. } ?> <?php // this part updates the database with the newly created business listing if (isset($_POST['submit'])) { $location = $_POST['location']; $company_name = $_POST['company_name']; $editor1 = $_POST['editor1']; // lets populate the database with this new information $q = ("UPDATE listings SET location='$location', company_name='$company_name', editor1='$editor1'"); $result = mysql_query($q) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); // success or failure ? if ($result) echo "<p align=\"center\"><u>The newly edited listing was successfully inserted into the Listing's database</u></p>"; else echo "<p align=\"center\"><font color=\"red\">There was a problem, the data got lost on the way.</font></p>"; } }else { /* Link back to main */ header("Location: index.php"); } ?> <!-- ##### END OF EDITING AND SENDING THE EDITED HTML TO THE "LISTINGS" db TABLE ##### --> </div><!-- /editor --> </div><!-- /editor_wrapper --> <!-- START OF FOOTER --> </div><!-- /wrapper --> </body> </html>
  13. I have a script on my server that downloads, decompresses and decodes gzipped xml data for editing in a textarea, after editing i am base64 encoding and gzcompressing this xml data to save in MySQL this is the code that i use <?php if(isset($_POST['submit'])){ $xml = $_POST['xml']; $xml = ('SWFT' . base64_encode(gzcompress("$xml"))); $xml = substr($xml, 0); mysql_query("UPDATE users SET xml='$xml' WHERE id='$_SESSION[user_id]'"); $result = mysql_query($query); } ?> as you can guess it just saves the data as an encoded text to make it work as a gzipped file it needs echoing in a textarea and pasting into notepad (or similar ) and saved manualy as an xml.gz file What i am trying to get around is having to do the notepad thinggy, how can i get it to save the file and store in the db in a BLOB filed as a xml.gz i know this is the way to go http://www.bigresource.com/Tracker/Track-mysql-Bm92u4gR/ but how can i assign it a name whilst encoding/compressing and updating into MySQL at the same time?
  14. Told you i was a newbie..lol, i didnt put a form method in , works ok now with post, thanks for pointing me in the right direction
×
×
  • 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.