I need help with posting a value to a php script from a js function called by an onclick event in an HTML page. Any help would be appreciated.
I have a link to the Google hosted jQuery library.
I am rendering a page with php with a submit button whose onclick action is seen below as updateSession() which posts a value to a php script that is supposed to update a MySQL table.
I can step through the script wile executing, using Fire Bug, but once it steps back out of the jQuery library no action or messages that I can see.
---------- script details
Part of the echo statement from the php rendered html page:
<input type=\"submit\" value=\"Submit\" class=\"close\" onClick=\"checkCode()\"/>
The js function called by the submit action (i commented out my original attempt but left in place for comments):
function updateSession (){
//$.post( "includes/update.php", { action: "y" });
jQuery.ajax({
url: "includes/update.php",
type: "POST",
processData: false,
contentType: "text",
data: { 'action': 'y'},
success: function( data ) { // for debugging
alert( data );
}
});
}
The php script being called with the jQuery .ajax:
<?php
//session_start();
require("includes/config.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db) or die ( "Data Server Error");
// connect to db
// get session id from $_POST parm
// add session id + validation marker to sessiondata table
$action = mysql_real_escape_string($_POST['action']);
//$idSession = SESSION_ID();
$idSession = "sdfwe54645gaerg";
$setCouponStateSql = "INSERT INTO appdata values ($idSession, $action);";
$executeUpdate = mysql_query($setCouponState);
?>