views:

162

answers:

3

Hello,

I have the following PHP code pasted here:

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

Which produces the following html code:

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

My problem is that the popup window is not created, or if it is created that it is empty. I have used JSON encode as previously suggested, but that does not seem to work.

Also, no image is displayed, despite PIC_URL being a correct image. apprantly this is because of an unclosed style tag, however I do not know why that is being generated, or how to prevent it.

I would also like to know the best way to insert newlines into my php, so the generated html is not a contiguous block.

edit: ARTICLE_DESC is definitely not empty, despite what people are saying. However, I have used a different record to double check, and there is still the same problem, although img src and document.write are n o longer blank. The resulting html is here:

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

It definitely seem to be a problem with the unclosed <style ty tag, but I see nothing responsible for generating that in the php

A: 

Have you try without json_encode? Maybe this function returns bad value?

lfx
I tried without JSON encode, and everybody said to use JSON encode.
Joshxtothe4
JSON Encode returns a blank string in this case, indicating that there's no data to encode. Others would have problems if it didn't work.
The Wicked Flea
A: 

Putting the HTML markup into your .js file, AJAX fetching just the values returned by MySQL query and plugging them in could fix it, not sure if this can be applied in your situation though. I think the & in "Ed Hardy Damen T-Shirt Skulls & Butterfly, Gr.M Neu+OVP" may be what breaks the whole thing, tried it on an entry without & in it?

mike nvck
the html comes from a variable, and is not always in my control, so a fix like that is not useful
Joshxtothe4
Rich Bradshaw
A: 

The picture is not displayed because you have <img src=""/>, which obviously isn't pointing anywhere. I would print_r($row) for a test and make sure that $row['PIC_URL']; is valid.

It also looks like $row2["ARTICLE_DESC"] has got nothing in it - I would check that your second query is actually returning a record - try doing something like:

$htmlset = mysql_query($sql2);
if (!$htmlset) die ('cannot find html description..');

Edit

It looks like lower down in the page your data from the database contains malformed HTML. It maybe worth putting this line in:

$row = array_map('htmlspecialchars', $row);

directly beneath the line while ($row = mysql_fetch_array($result))

This will cause the bad HTML to be displayed literally rather than parsed as HTML by the browser, and it should therefore not break the rest of the page.

Tom Haigh
This is the problem though. Both ARTICLE_DESC and PIC_URL are valid, and defnitly contain data. It is only by adding the script to try and have a pop-up window that they are empty.
Joshxtothe4
what would happen if article_desc contained its own script tags?
Joshxtothe4
The script stuff is just another echo statement. It won't affect how the other data is being outputted. If you don't believe this comment out the script stuff and I think you will still have the same problem
Tom Haigh
Does this mean there is no way to show the html in a popup if it is malformed? if that is the case, is there any way to trap for an error so good html can be showin in the popup?
Joshxtothe4
It's tricky if you are not in control of the HTML, if it is malformed then it is unlikely that the browser will correctly display it. Where are you getting it from and how is it getting into your DB - are you entirely sure that process isn't affecting the data?
Tom Haigh
You could look at libraries that will attempt to clean up HTML, but I would try to fix it at the source first
Tom Haigh
The html is saved in a database that retrieves ebay auctions. This database is then exported to a csv file and imported into mysql, wherein by it is retrieved from ARTICLE_DESC. The original html is at: http://www.nomorepasting.com/getpaste.php?pasteid=22492 If it is getting garbled is it fixable?
Joshxtothe4
I think this is to do with your CSV parsing - it looks like maybe the HTML is getting split into multiple fields - possibly because of the double quotes. can we see the csv file?
Tom Haigh