I want to query a value from mysql with php, assign the value to a variable, echo the php variable in some JavaScript and have the value be displayed in an iframe.
I just can’t get it to work…
My PHP:
<?php
$text_id = $_GET['text'];
$stmt = $dbConnection->prepare("SELECT * FROM content WHERE id=:id");
$stmt->bindParam(":id", $text_id);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $row)
{
$text = $row['text'];
}
?>
My JavaScript:
(The function is called with <body onLoad="iFrameOn();">)
function iFrameOn()
{
richTextField.document.designMode = 'On';
window.frames['richTextField'].document.body.innerHTML = <?php echo json_encode($text); ?>;
}
I solved the problem. I had the file saved as .js, and of course in order to use php the file must be .php. Sorry for the stupid mistake and thank you very much for all of your answers.