Mário Correia Mário Correia - 5 months ago 10x
HTML Question

document.title funcion can't set it work with php

I have this line of code

<script type="text/javascript">
document.title = "<?php include('pot1.php');?>"

My pot1.php gives me an echo with one random number, but that code does not seem to work and I don't know why the echo doesn't appear in my title. Is anything wrong with the code?

pot1.php code:

$cg = fetchinfo("value","info","name","current_game");
$cb = fetchinfo("cost","games","id",$cg);
echo '$'.$cb;

This echo is working and is giving me values because I can see them in one div.


You should just do it like this:

<?php include('pot1.php');?>

Now we know that there is a variable set. Echo that into the title tag.

<script type="text/javascript">
    document.title = "<? echo $cb ?>"

The way you're doing it now... I don't think you can include an entire PHP page and expect to behave like a simple string, even if that's all it returns.