Click to See Complete Forum and Search --> : Java in the php


Beffic
05-26-2009, 03:27 AM
Okay so I am not sure how I would do this but I have a inventory script going and I am not sure how to put javascript into php.


Any help?

<?php
include("../../connect.php");
if(!isset($_COOKIE['player_id']))
die('Please login.<br><a href=../../index.php>Go back</a>.');
$Player=$_COOKIE['player_id'];
$Query="SELECT * from Users where ID='$Player'";
$Query2=mysql_query($Query) or die("Could not get user stats.");
$User=mysql_fetch_array($Query2);
if($_COOKIE['password'] !=md5($User['Password']))
die('Your Password doesnt seem right for this account. <a href=../../index.php>go back</a>');
?>
<script type="text/javascript">
function unequip()
{
<?php $new= ?>document.getElementById("item")
<?php mysql_query("UPDATE `Inventory` SET Equipped='No' WHERE Name='$new'"); ?>
}
function equip()
{
<?php $new= ?>document.getElementById("item")
<?php mysql_query("UPDATE `Inventory` SET Equipped='Yes' WHERE Name='$new'"); ?>
}
</script>
<?php

$Truvo=mysql_query("SELECT * FROM `Inventory` WHERE Owner='$Player' ORDER BY Equipped LIMIT 15") or die("The inventory died!");
$colors=Mysql_query("SELECT Equipped From Inventory WHERE Owner='$Player'");
if($colors=="Yes"){
$color=CC0000;
$equip=unequip();
}else{
$color=FFFFFF;
$equip=equip();
}
while($Item=mysql_fetch_array($Truvo)){
print"<input type=\"text\" name=\"item\" ondblclick=\"".$equip."\" value=\"".$Item['Name']."\" style=\"background-color: ".$color.";\" readonly>";
}
?>


error:
Parse error: syntax error, unexpected ';' in /home/riseofim/public_html/riseofimmortals.com/Main/inventory.php on line 15

bradgrafelman
05-26-2009, 02:27 PM
Javascript (not to be confused with Java) and PHP are languages on opposite ends of the spectrum; PHP is server-side code. All of the PHP code is evaluated and processed, the output of which is then sent to the user's browser. Once the user's browser receives the script's output, it then processes the data - this is when your Javascript code gets read and parsed as well.

You'll either have to use a form and submit data back to your PHP script, or else you'll have to look into solutions that use AJAX to post data behind the scenes and update the page accordingly.