<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function SwitchImage()
{
document.theImage.src = "<?php echo $row['image1']; ?>";
}
</script>
<body>
<?php
require_once('MyConn.php');
$query = "SELECT * FROM table WHERE name='variable";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
?>
<p><img src="<?php echo $row['image1'] ?>" name="theImage" onclick="SwitchImage()"></p>
Is it possible to call to a MySQL database, with PHP through a Javascript function???
I have no problem connecting to the database and retrieving the info. I also have no problem changing the image source, but when I try to call the value with PHP in the javascript function, I get nothing (i.e. it just leaves document.theImage.src blank). However, if I put:
document.theImage.src = "<?php echo 'image.jpg' ?>";
it will work.......