I am using the Jquery/Ajax API to update a relevant database with the information the users enter when signing up for their account. Once the data has been successfully sent I need to open another page where the user can upload their user photo. The form handling PHP page that my data is sent to uses the PDO function to grab the last inserted id into my table $users_ID_count = $dbh->lastInsertId();. It then echos back $users_ID_count to my success function within AJAX where I was under the intention i could open my pic upload page with the ID as a parameter. I cant seem to be able to use the ID passed in the URL and am widely open to a better solution.
var dataString = 'name1='+ first + '&last1='+ last + '&email1='+ email + '&password1='+ password + '&user1=' + usrname + '&dev=' + dev + '&des=' + des + '&bth=' + bth;
// AJAX Code To Submit Form. jquery version
$.ajax({
type: "POST",
url: "blog-signup-srvr-4.php",
data: dataString,
cache: false,
success: function(text){
window.location.assign('http://localhost/knoxPrograms/knoxville_programmers/blog-signup-propic.php?disatl ='+ text);
}
});
below is the blog-signup-srvr-4.php sorry that it drags quite long
if(isset($_REQUEST['name1']) && isset($_REQUEST['last1']) && isset($_REQUEST['email1']) && isset($_REQUEST['password1']) && isset($_REQUEST['user1']) && isset($_REQUEST['dev']) && isset($_REQUEST['des']) && isset($_REQUEST['bth']))
{
//career type field values
$dev = $_REQUEST['dev'];
$des = $_REQUEST['des'];
$bth = $_REQUEST['bth'];
//su form field values
$firstName = $_REQUEST['name1'];
$lastName = $_REQUEST['last1'];
$emailAddr = $_REQUEST['email1'];
$usrPass = $_REQUEST['password1'];
$userId = $_REQUEST['user1'];
setUpUser($dev, $des, $bth, $dbh, $firstName, $lastName, $emailAddr, $usrPass, $userId, $dbh);
}
//initial set up function. Prepare sql statements, bind parameters to users input and send
function setUpUser($dev, $des, $bth, $dbh, $first, $last, $email, $pass, $id, $dbh)
{
$stmt = $dbh->prepare('INSERT INTO users(userName, userPass) VALUES(? , ?)');
$stmt2= $dbh->prepare('INSERT INTO userinfo(firstName, lastName, email, ID, careerType) VALUES(?,?,?,?,?)');
$dbh->beginTransaction(); //the start of paramater binding and execution
$stmt->bindParam(1, $id);
$stmt->bindParam(2,$pass);
$stmt2->bindParam(1,$first);
$stmt2->bindParam(2,$last);
$stmt2->bindParam(3,$email);
//one of the following sends the string 'true' over, the value
//of the element that sends true over is what is updated in our database
if($dev == "true"){
$dev = "dev";
$stmt2->bindParam(5, $dev);
}
elseif($des == "true"){
$des = "des";
$stmt2->bindParam(5,$des);
}
elseif($bth == "true"){
$bth = "bth";
$stmt2->bindParam(5,$bth);
}
$stmt->execute();
$users_ID_count = $dbh->lastInsertId();
$stmt2->bindParam(4,$users_ID_count); //bind parameter after the first statement has been created and its last id insert is stored
$stmt2->execute(); //execute after last id inserted is binded to parameter so we may enter it into our database
$dbh->commit();
echo $users_ID_count;