Html mangled from php

I have a mysql database that contains html description as one of the fields. This description is out of my control, and it is obtained and inserted automatically. An example of one of these descriptions is shown below:

http://www.nomorepasting.com/getpaste.php?pasteid=22492

The data is initially exported from the access database and appears to remain intact. Example of exported data:

http://www.yousendit.com/transfer.php?action=batch_download&batch_id=TTZtWmdsT01kMnVGa1E9PQ

I am trying to output a variable containing the html description in a popupwindow so that it can be displayed as is. The code I'm trying to use for this is located here:

http://www.nomorepasting.com/getpaste.php?pasteid=22498

However, it generates the following html code:

http://www.nomorepasting.com/getpaste.php?pasteid=22462

There is a hidden style tag that prevents the rest of the page from being displayed, and a winbdow popup. As far as I can tell, I have limited this to a php task because the data appears to be fine in mysql.

edit:

I just tried to select only article_Desc from the database with this code:

http://www.nomorepasting.com/getpaste.php?pasteid=22494

What caused this as a result:

http://www.nomorepasting.com/getpaste.php?pasteid=22496

edit2:

There seems to be a problem with the countrycode variable containing the style tag. When I remove this, the image is displayed and a popup is created, but only with the html results, like the previous link I pasted in. The data in the database seems to be correct, so what might be causing this problem?

0


source to share


2 answers


The CSV file is a bit of a mess. It looks like the fields are separated by tabs and are not enclosed by anything. This might be OK for simple data, but when you start nesting HTML you will have problems - looking at one of your other questions , it looks like the CSV parser is getting confused and splitting one HTML field into several - this seems to happen every time. when it comes across a tab (and maybe double quote as well?)

Can you change the format of the CSV file? I would assume that you are using commas to separate fields, and that you are defining a shell character (like a double quote) for more complex strings like HTML - I think you need to make sure that any double quotes inside the string escaped as well. Also keep in mind that you may need to remove or avoid line breaks from these lines depending on what is parsing it, but I'm not entirely sure about that.

Edit after your comment

You don't need to worry about the delimited line as long as it's wrapped in a charactor. If you want a string containing three fields and three string values:

String1
String2
Stri,ng3

      

The next one is not valid and will be treated by the parser as four fields

String1,String2,Stri,ng3

The following is valid because the divisor is "enclosed" with a double quote

"String1", "String2", "Stri,ng3"



Now it gets tricky when you want to have a double quote inside a string - then it will need to be escaped. If you want to present

String1
String"2

      

CSV field can be escaped like

"String1", "String\"2"

      

If I remember correctly, you imported into MySQL using LOAD DATA ?, so for the above examples, you can use options like

FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\'

      

I'm not sure how MySQL will handle line breaks on closed lines, I can't find much about it. If it reads the file in turn, you might need problems.

Edit 2

If the rest of the problem is with a line break, you can replace the line \n

with \\n

with \\n

and \r

with \\r

in the code that exports each field to CSV

+1


source


Reminds me a little of this question .

You see here in PHP code

child1.document.write(' . json_encode($row2["ARTICLE_DESC"]) . ');

      

and here in the HTML code

child1.document.write("");

      

This means that json_encode ($ row2 ["ARTICLE_DESC"]) outputs "". And since json_encode ('') outputs "", it means that $ row2 ["ARTICLE_DESC"] is empty.

EDIT:

$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";
$sql2="SELECT ARTICLE_DESC FROM Auctions WHERE ARTICLE_NO ='$pk'";

      

There is no need for a second sql2 as the first $ sql should already include ARTICLE_DESC. So

  • ARTICLE_DESC field is empty for ARTICLE_NO.
  • ARTICLE_DESC is an invalid name.
  • ARTICLE_DESC is in another table.

CHANGE IMAGE:

$query = "SELECT article_desc FROM Auctions WHERE ARTICLE_NO ='220288560247'";

      



The article_desc name is not ARTICLE_DESC.

EDIT COMMENTS:

Change all occurrences of ARTICLE_DESC to article_desc.

EDIT Now that you got your html code you need to replace

json_encode($row['article_desc'])

      

with this

str_replace(array("\n", "\r", "\t"), array('', '', ''), $row['article_desc']);

      

which can be done in a nice function. Just remember that all the html code you are typing is in

<!-- text -->

      

so you don't see anything in the new window ...

<!-- +++++++++++++++++++++++++ Bitte Γ€ndern Sie im eigenen Interesse nichts an diesem Code! ++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++ Das kann massive Fehldarstellungen ihrer Auktion zur Folge haben! +++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++ ++++++++++++++++++++++++++ Ihr Supreme Team +++++++++++++++++++++++++++++++++++++++++ -->

      

+2


source







All Articles