I have saved the javascript in a mysql(phpMyAdmin) database. When I display it on the front end from the database using php it is showing as string, not as javascript. Here is the javascript code in mysql:

   <script type="text/javascript" src="http://i0.poll.fm/survey.js" charset="UTF-8"></script>
   <noscript><a href="http://rohan44.polldaddy.com/s/test">Take Our Survey!</a></noscript>
   <script type="text/javascript">
     polldaddy.add( {
       type: 'button',
       title: 'Take Our Survey!',
       style: 'inline',
       text_color: '000000',
       domain: 'rohan44.polldaddy.com/s/',
       id: 'A8D2AA9FAF96DA61'
     } );
   </script>   

The php page:

  <?php $xy=mysql_query("select * from survey where id=1");
   $row=mysql_fetch_row($xy);
   echo '<div id="survey">'.$row[1].'</div>'; ?>

How can this work as javascript?

share|improve this question
7  
I don't even know where to start ... – rdlowrey Jun 5 '12 at 20:06
@rdlowrey: with a stiff drink – Dancrumb Jun 5 '12 at 20:07
In the front end it is reading string not the javascript tag. – user1429132 Jun 5 '12 at 20:10
Do you want it to display just the javascript code? Or actually insert the script into your page? – jeschafe Jun 5 '12 at 20:11
can you please clarify what "it is reading string" means? – Crayon Violent Jun 5 '12 at 20:13
show 5 more comments
feedback

1 Answer

First try commenting your echo line in the PHP and put this in its place:

var_dump($row);

This will let you see all the data in $row. I suspect that your script data is not in $row[1] but maybe in $row[2]. By using var_dump, you will see everything that is in $row and where it is.

If, after checking $row with var_dump, you don't see your data in there anywhere, you then need to make sure your query is correct. Run the query yourself and see what results you get. If you see the correct results when you run the query, make sure that the database is selected in the script. You may have to do something like

mysql_select_db("mydatabase");

First before your query will work.

share|improve this answer
It's probably in row[0], but regardless he's piping javascript from a database into a php response? He should probably just include it from a file. Why use a database for that? – Nathaniel Ford Jun 6 '12 at 0:04
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.