2
Hi. I was wondering how can I pass the $_SESSION code to a variable
if ( isset($_SESSION['codigoUsu']) ) {
$codigoUsuario=$_SESSION['codigoUsu'];
inserirVenda($codigoUsuario,$codigoProduto);
header("Location: produtosSelecionados.php");
}
Edited question
controleVenda
<?php
include 'crudVenda.php';
session_start();
$opcao=$_GET['opcao'];
if($opcao=="selecionar"){
$codigoProduto=$_GET['codigoProduto'];
if(isset($_SESSION['codigoUsu'])){
$codigoUsu=$_SESSION['codigoUsu'];
inserirVenda($codigoUsu,$codigoProduto);
}
header("Location: produtosSelecionados.php");
}?>
crudVenda
<?php
include 'conexaoBD.php';
function inserirVenda($codigoUsuario,$codigoProduto){
conectar();
query("INSERT INTO venda (codigoProduto,codigoUsuario) VALUES ($codigoProduto,$codigoUsuario)");
fechar();
}
?>
What exactly doesn’t work on your code snippet? Are you going to use this variable elsewhere? You are starting the section on the page products.php? Ever tried to give a
var_dump()
in its variable?– Lauro Moraes
I take this $code and insert it into the bank and it goes to this page where you selected this product. But it is giving an error where it says q n recognizes the codeUsu. I am starting the session on another control page.
– igorvp
I have a page where are the products to select. Clicking there it goes to the controlVenda which is the page where I get what is sent from the page that has the products selectable. In this page of control I need to take the user code via session to send to function and insert in the bank
– igorvp
It is needed by simple quotes on the variables present in the VALUES of the sql command.
– Igor Serafim