Welcome Guest, Not a member yet? Register   Sign In
flexigrid - pass variable via ajax
#1

[eluser]Unknown[/eluser]
I'm having problems passing a variable via ajax, to my db. When my user enters a new row of data and presses save, here is what I am doing:
Code:
if (com=='Save')
        {
           if($('.new',grid).length>0){
            $.ajax({
               type: "POST",
               dataType: "json",
               url: "save.php",
               data: { firstname: $('#firstname').val(), lastname: $('#lastname').val(), homephone: $('#homephone').val(), cellphone: $('#cellphone').val(), email: $('#email').val(), job: $('#job').val() },
               success: function(data){
                       alert("Thank you for volunteering!");
                   $("#flex1").flexReload();
               }
             });
            }

Two questions: first, can I send a variable via the url? In other words, in the file above I have done a get to get the value of "gameno". I need to pass this variable thru to save.php, to be saved in my db. How do I do this? Second question, I never get to the success function, event ho my data is saved in the db. I've put my save.php file below - can you see where I've gone wrong???

$gameno = $_GET['gameno'];
error_log("gameno is $gameno", 0);

[code] save.php

<?php

include ("concession-connection.php");
$table = "varsitygames";
$gamenumber = $_POST['gameno'];
writeLog("in save - gameno is ");
writeLog($gamenumber);

if(isset($_POST['lastname']) && isset($_POST['firstname'])) {
$link = mysql_connect($host, $user, $password);

if(!is_resource($link)) {
echo "Failed to connect to the server\n";
// ... log the error properly
} else {
// Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON.
if(get_magic_quotes_gpc()) {
$lastname = stripslashes($_POST['lastname']);
$firstname = stripslashes($_POST['firstname']);
$homephone = stripslashes($_POST['homephone']);
$cellphone = stripslashes($_POST['cellphone']);
$email = stripslashes($_POST['email']);
$job = stripslashes($_POST['job']);
$gamenumber = stripslashes($_POST['gameno']);
writeLog("magic quotes\n");
} else {
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
}

$date = "0000-00-00";

// Make a safe query
$query = sprintf("INSERT INTO $database . $table (date, gamenumber, lastname, firstname, homephone, cellphone, email, job ) VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$date, $gamenumber, $lastname, $firstname, $homephone, $cellphone, $email, $job);

$result= mysql_query($query, $link) or writeLog ("Query failed: " . mysql_error());
}

}

?>




Theme © iAndrew 2016 - Forum software by © MyBB