我有一个表单上提交我想要它做的两件事情: 1)存储值在数据库 2)写$ _ POST值到PDF如何在php中提供多个“提交”按钮?
我对数据库的脚本编写和它的工作原理在其自己的。我有另一个写入PDF的脚本,它也可以正常工作。
但是,当我尝试在另一个结束时调用一个函数时,提交操作仅执行其中一个操作。我该如何解决这个问题。我希望我的按钮同时执行store.php和makepdf.php
目前,我只能在表单的action标签中指定一个表单。
编辑:我在这里添加脚本。
这里是(串联为长度的限制)我store.db文件:
<?php
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
// GET ALL THE VARIABLES FROM THE FORM
$FirstName= $_POST['firstname']?$_POST['firstname']:'0';
$LastName= $_POST['lastname']?$_POST['lastname']:'0';
$Email= $_POST['email']?$_POST['email']:'0';
$idn= $_POST['idn'];
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn) {
die('Could not connect: ' . mysql_error());
}
$sql1 = "INSERT INTO borrower(FirstName,LastName,Email,ssn) VALUES('".$FirstName."','".$LastName."','".$Email."','".$idn.");
mysql_select_db('db');
$retval1 = mysql_query($sql1, $conn);
}
//Test successs
//echo "Successful"
?>
这里是我的makepdf.php:
<?php
function pdfMaker() {
include('fpdf/fpdf.php');
include('fpdi/fpdi.php');
$FirstName;
$LastName;
$Email;
$IDNumber;
// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('rcpp1.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);
// now write some text above the imported page
$pdf->SetFont('Times', '', 9);
$pdf->SetTextColor(0,0,153);
// Top Left stuff
$pdf->SetXY(9, 38);
$pdf->Write(0, $Firstaname.$LastName.$Email.$IDNumber);
$pdf->Output(($Firsname."_".$Lastname.'file.pdf'), 'D');
}
pdfMaker();
?>
这里是我的表格:
<form class="form-horizontal" method="post" action="">
<fieldset>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="firstname">First Name</label>
<div class="col-md-4">
<input id="firstname" name="firstname" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="lastname">Last</label>
<div class="col-md-4">
<input id="lastname" name="lastname" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-4">
<input id="email" name="email" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="idn">ID#</label>
<div class="col-md-4">
<input id="idn" name="idn" type="text" placeholder="" class="form-control input-md">
</div>
</div>
</fieldset>
</form>
再次,当我添加任何PHP脚本的形式在行动标签,每个功能单独罚款。但是,如果尝试向另一个脚本添加一个函数或从另一个脚本调用它,它只会执行一个并停止。
,而不能看到你的代码中,我们只能推测....我们不这样做非常好。 –
首先我包含所有三个脚本? – Tendi
表单一次只能提交一个网址。你为什么要“提交按钮”做两件不同的事情?是不是表单提交给任何形式的工作?这个脚本是'<?php job1();这是微不足道的。 JOB2(); ?> –