2011-12-29 44 views
-1

我有一个页面,它将输入到上一页中的数据输入到数据库中。然后它获取该帖子的数据库ID。我想在标题中使用这个id($ id),但是当我运行下面的代码时,get变量是空的。PHP标题不重定向获取变量

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> 
+0

是mysql_query()做它的工作(它插入行)? – 2011-12-29 04:34:48

回答

3

你没有定义$id直到右底。

如果要在代码中使用header(),请在开始处输入ob_start()

+1

或发送标题和html之前做所有处理... – DGM 2011-12-29 04:36:25