PHP:在DataBase中插入后打印post值

时间:2014-09-05 21:47:24

标签: php mysql

我使用php在表用户中插入数据。

插入后,我用

进入同一页面
  $url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        header('Location: '.$url."&sent=yes");

因此页面刷新了,我需要打印PDF才能为该用户打印文件。我想使用POST发送到Print.php名称和social_security_number。我可以在Print.php中使用GET这样做:

$insertGoTo = "Print.php?ssn=".$_POST['social_security_number'];

并在Print.php中

$find_ssn = $_POST[ssn];

但是$ _POST [ssn]是空的,我能以$_POST[ssn]做同样的值

我的代码: -

if(isset($_POST['submit'])) {

// sql insert to DB
mysql_query("INSERT INTO `olmaa` ( `aid` , `firstname` , `fathername` , `familyname` , `bday` , `bmonth` , `byear` , `bpcity` , `bpstate` , `bpcountry` , `nationalty` , `placenow` , `jobs` , `degree` , `degreespical` , `enjazat` , `moalef` , `moassa` , `nameofjeha` , `namemasol` ,`tell` , `fax` , `email` ,`maswgha`,`cv`,`work`,`date` )
VALUES ( '".$aid."', '".$firstname."',  '".$fathername."',  '".$familyname."',  '".$bday."',  '".$bmonth."',  '".$byear."',  '".$bpcity."',  '".$bpstate."',  '".$bpcountry."',  '".$nationalty."',  '".$placenow."',  '".$jobs."',  '".$degree."',  '".$degreespical."',  '".$enjazat."',  '".$moalef."',  '".$moassa."',  '".$nameofjeha."', '".$namemasol."', '".$tell."',  '".$fax."',  '".$email."',  '".$maswgha."' ,  '".$filenameword."' ,  '".$filenamezip."' , '".time()."') "); 

$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        header('Location: '.$url."&sent=yes");
}

if(isset($_GET['sent']) && $_GET['sent']== 'yes'){ 
?>
<form name="pt_list" action="classes/aplay_pdf.php" method="post"><br/>
<input type="submit" name="pdf"  value="PDF">
</form>
<?
}
?>

2 个答案:

答案 0 :(得分:2)

你错过了$_POST[ssn]周围的引号; 还有 - 从我在这里看到的,您引用的是GET变量,而不是POSTGET Variable = URL | POST Variable = Background

您的代码必须如下所示:

$insertGoTo = "Print.php?ssn=".$_POST['social_security_number'];
$find_ssn = $_GET['ssn'];

答案 1 :(得分:0)

您确定没有抛出关于常量的错误吗?如果不。打开错误报告,你的$ _POST数组中缺少引号:

$find_ssn = $_POST['ssn'];

另外。由于数据被附加到URL,因此您不应该使用$_POST,因为您要查找$ _GET值:

$find_ssn = $_GET['ssn'];