I am passing a value to a function. In the function, I use PHP code to accomplish my task. I need to imbed the value passed into the function into the PHP string.
Here is the function:
<script type="text/javascript">
function getData(p1) {
alert("Variable is: " + p1);
<?php
$club=window.title.value;
$username="user";
$password="password";
$database="database";
$datahost="example.db.4729287.hostedresource.com";
mysql_connect($datahost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM golfinfo WHERE clubname = 'Mirabel'";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?> alert("row is: " + p1);
window.ClubName.value= "<?php echo $row['ClubName'] ?>";
window.Privacy.value = "<?php echo $row['Privacy'] ?>";
window.Membership.value = "<?php echo $row['Membership'] ?>";
window.Type.value = "<?php echo $row['Type'] ?>";
}
</script>
This function is called as follows:
I would like to replace the: WHERE clubname = 'Mirabel' with the parameter p1 like: WHERE clubname = p1
I am at a loss to find a way to imbed the p1 into the string.
Any suggestions? Thanks
mysql_connectand othermysql_functions are deprecated as their documentation clearly states. Better use an alternative such as PDO. 2. This is not just about embedding a variable in a PHP string, but about calling a piece of PHP from JavaScript. This isn't as easy as you make it. You can't mix JavaScript and PHP like this at all. PHP runs on the server, JavaScript on the client, and you can't just mix them.