0

i'm doing a project in php! the problem is array is not printing properly. Actually im trying to retrieve text data from mysql using php. im able to retrieve the data, but while im printing in the document it is not printing as i want!!

    echo "<td><p onclick=alert('".$arr[$t]."'); ><u>VIEW</u></p></td>";

$arr[$t] is text data i retrieved from database. it should print like this(assuming $arr[$t] has data "this is a paragraph")

but the actual output is like this..
output in CHROME

    <td><p  onclick="alert('this" is a paragraph'); ><u>VIEW</u></p></td>


output in FIREFOX

    <td><p paragraph');=""  a="" is=""  onclick="alert('this" ><u>VIEW</u></p></td>


i dont know why it's happening.
please help me out with this..
thanks in advance :)

1 Answer 1

1

The syntax highlighting from your chrome output gives it away - you have a double quote nested inside your double quotes, which is invalid HTML.

You should escape all output before rendering it, using something like htmlspecialchars (https://www.php.net/manual/en/function.htmlspecialchars.php).

Also, you should wrap your onclick handler in quotes - eg. onlick="alert('stuff stuff more stuff')" or it won't parse correctly.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your reply sevenseacat! actually if the text data is single word,it's working properly.. if text data has more than 1 word, first word is printing in between double quotes.. remaining words are printing after quotes.. thats the exact problem!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.