0
I am making a program and on the first page insert a series of values typed by the user in the bank and Gero a id
. After that I would like to return the value to the AJAX function and redirect to another page by passing this id
as a parameter. Someone can help me?
Inserting into table (instead of returning 1
in the variable cadastro
, would like to return the entered registration code):
$sql = 'INSERT INTO incidente (titulo, descricao, anonimo, tipo, foto)';
$sql .= 'VALUES (:titulo, :descricao, :anonimo, :tipo, :foto)' ;
try {
$recebeConexao = $pdo->prepare($sql);
$recebeConexao->bindParam(':titulo', $_POST['titulo'], PDO::PARAM_STR);
$recebeConexao->bindParam(':descricao', $_POST['descricao'], PDO::PARAM_STR);
$recebeConexao->bindParam(':anonimo', $_POST['anonimo'], PDO::PARAM_STR);
$recebeConexao->bindParam(':tipo', $_POST['tipo'], PDO::PARAM_STR);
$recebeConexao->bindParam(':foto', $_POST['img'], PDO::PARAM_STR);
$recebeConexao->execute();
if($recebeConexao == true){
$cadastro = 1;
}else{
$cadastro = 0;
}
} catch (PDOException $ex) {
echo "Erro inserção";
}
echo (json_encode($cadastro));
?>
AJAX function (I would like to call the other page by sending the value of id
):
function enviar(){
var formula = $('#formCliente').serialize();
var img = document.getElementById('smallImage').innerHTML;
$.ajax({
type:'POST',
data:formula,
url:'http://ip/connect/www/criar_incidente_camera.php',
success: function(data){
if(data == '' || data == 0){
alert('Usuário ou senha incorreto' + data);
window.location = "";
}
if(data == 1){
alert('Seja Bem-vindo!' + data);
window.location.href = "mapa_incidente.html";
} else {
alert('outro' + data);
}
}
Thank you for your attention!
Which database?
– Vinícius Gobbo A. de Oliveira
tried $Pdo->lastInsertId();
– Marcelo Bonus