Hi all,
Im afraid its another noob question...lol. Being relatively new to javascript/ajax/jquery..programming ingeneral... I am fumbling where blind men drive chariots, so please go easy:). I am wanting to post 3 values to the database, 2 of which are results of a mysql query(Im not sure if I am doing this right, so feel free to correct me..lol..please). Looking at the source code, var userid has the correct value of the users id. The second(var obid), and third(var authoruserid) values. The rows returned from the query are empty when I check the source code, and the values in firebug are just simply the name of the var. The data is also not being posted to the database.
Can you pick my mistake?:P...lol
Any help is always appreciated.
Updated: Sunday, 5th April AEST
This question still remains unanswered. I really would be happy if someone could just tell me that I am doing the ajax part right, and that ajax can use sql rows as data, then I can begin to look for other reasons why this isnt working.
Thanks all.
Server side:
if( isset( $_POST['user_id'] ) && isset($_POST['ob_id'] ) && isset( $_POST['author_user_id']) ) {
$result = mysql_query("INSERT INTO ilike (ilike_user_id, ilike_object_id, ilike_author_user_id) VALUES (" . mysql_real_escape_string( $_POST['user_id'] ) . ", " . mysql_real_escape_string( $_POST['ob_id'] ) . ", " . mysql_real_escape_string( $_POST['author_user_id'] ). ")" );
echo $result ? 'Vote Succeeded' : 'Vote Failed: ' . mysql_error();
exit;
}
$status = $rows['status_id']; // done via a separate query
$aid = $rows['user_id']; // as above
$user_id = uid(); // User cookie check function
HTML:
<a href="javascript:;" onclick="updateScore(this)" class="blue">Vote</a>
Javascript:
<script type="text/javascript">
function updateScore( answer )
{
var userid = '<?php echo $user_id; ?>';
var obid = '<?php echo $status_id; ?>';
var authoruserid = '<?php echo $aid; ?>';
if ( confirm( "Are you sure?" ) )
{
$.post('index.php', {user_id: "userid", ob_id: "obid", author_user_id: "authoruserid"}, function(d)
{
alert('Vote Accepted: ' + d);
$(answer).after("<span>You Voted!</span>").remove();
});
}
}
</script>
Source code:
<script type="text/javascript">
function updateScore( answer )
{
var userid = '5';
var obid = '';
var authoruserid = '';
if ( confirm( "Are you sure?" ) )
{
$.post('index.php', {user_id: "userid", ob_id: "obid", author_user_id: "authoruserid"}, function(d)
{
alert('Vote Accepted: ' + d);
$(answer).after("<span>You Voted!</span>").remove();
});
}
}
</script>