I have a page that takes data entered in a previous page and inputs that data into a database. It then takes the database id of that post. I want to use this id ($id) in the header, but when i run the following code, the get variable is empty.
CODE:
<?php header("Location: http://localhost/biology/question.php?q=$id"); ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<?php
include '../connect.php';
if (isset($_POST['questionSubmit'])){
$question=mysql_real_escape_string($_POST['question']);
$detail=mysql_real_escape_string($_POST['detail']);
$date=date("d M Y");
$time=time();
$user=$_SESSION['id'];
$put=mysql_query("INSERT INTO questions VALUES ('','$question','$detail','$date','$time','$user','biology','0')");
$id=mysql_insert_id();
}
?>
</body>
</html>
You’re not defining
$iduntil right at the end.If you want to use
header()in your code, putob_start()at the beginning.