Hi,
I’m a low-intermediate programmer and I am having problems conceptually grasping how I can use Javascript to grab a PHP session variable and change a form button’s innerHTML, as well as enabling or disabling it depending on the PHP Session variables.
Here is my code:
[CODE]
<?php if ((isset($_POST[‘submit_save’])) && (!isset($_SESSION[‘game_saved’]))
&& (isset($_SESSION[‘player_id1’]))) {
require_once (‘../mysql_connect_test.php’);
$query = “INSERT INTO games
SELECT NULL, game_date, p1_uname, p1_relationship, p1_name, p1wr, p1lr, p1tr,
p1wp, p1lp, p1tp, p1ws, p1ls, p1ts, p2_name, p2_uname, p2_relationship, type_game,
p1_md, p1_as, p2_md, p2_as, g1w, g1l, g1t, g2w, g2l, g2t, g3w, g3l, g3t
FROM games_temp WHERE game_id=$gid”;
mysql_query($query, $dbc);
if ($query) {
$_SESSION[‘game_saved’] = “game_saved”;
}
}
?>
<!–
These navigation buttons appear on 4 different pages
The ‘Save Game’ button is a form in and of itself to perform an insert query
into the database based on the php script above.
–>
<table align=”center” width=”378px”>
<tr><td height=”5px”></td></tr>
<tr>
<td width=”20%”><input type=”button” name=”score” value=”Score” style=”width:100%; height:25px; font-style:normal; font-variant:normal; font-weight:normal; font-size:8pt” onclick=”self.location.href=(‘score.php’)” /></td>
<td width=”20%”><input type=”button” name=”charts” value=”Charts” style=”width:100%; height:25px; font-style:normal; font-variant:normal; font-weight:normal; font-size:8pt” onclick=”self.location.href=(‘values_chart.php’)” /></td>
<td width=”20%”><input type=”button” name=”report” value=”Report” style=”width:100%; height:25px; font-style:normal; font-variant:normal; font-weight:normal; font-size:8pt” onclick=”self.location.href=(‘#’)” /></td>
<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
<td width=”20%”><input type=”submit” name=”submit_save” value=”Save Game” style=”width:100%; height:25px; font-style:normal; font-variant:normal; font-weight:normal; font-size:8pt” /></td>
</form>
<td width=”20%”><input type=”button” name=”new_game” value=”New Game” style=”width:100%; height:25px; font-style:normal; font-variant:normal; font-weight:normal; font-size:8pt” onclick=”self.location.href=(‘index.php’)” /></td>
</tr>
<tr><td height=”3px”></td></tr>
</table>
If you notice, my ‘submit’ button is a form onto itself, which causes a MySQL query to take place under certain Session variable conditions. It works fine, but I would like to change the innerHTML of this button to ‘Game Saved’, as well as disabling it after it has been once clicked. I am confused about what syntax to use, where to use it, and whether I use Javascript to grab the PHP variables, or PHP to manipulate the javascript.
This is a great forum! Some of you guys are truly wizards.
Thanks, Bill