我有一个代码,我从前一页通过表单GET方法收到两个变量($ isbn,$ eno),但如果我没有在我的页面上回显它,则这两个变量不起作用相同的代码是如下所示。
<?php
error_reporting(E_ALL);
require 'db/connect.php';
if(isset($_POST['generatereport']))
{
$isbn=$_GET['isbn'];
$eno=$_GET['eno'];
echo $eno; //if this is not done then i am not receiving data from database
echo $isbn; //if this is not done then i am not receiving data from database
$studentdata="select * from users where eno='$eno'";
if($studentresult=$db->query($studentdata))
{
$studentrow = $studentresult->fetch_assoc();
}
else
{
echo"fetching error";
}
$bookdata="select Lpad(isbn,'10','0') as isbn,book_name from book_data where isbn='$isbn'";
if($bookresult=$db->query($bookdata))
{
$bookrow = $bookresult->fetch_assoc();
}
else
{
echo"fetching error";
}
}
?>
<!doctype html>
<html lang='en'>
<head>
</head>
<body>
<div id='report'>
<table>
<tr><td><h3>Issue Report</h3></td></tr>
<tr><td><h4>Student details</h4></td></tr>
<tr><td>UNIQUE ID:<?php //random number here ?></td></tr>
<tr><td>Enrollment:<?php echo $eno; ?></td></tr>
<tr><td>Name:<?php echo strtoupper($studentrow['fname']);echo strtoupper( $studentrow['lname']); ?></td></tr>
<tr><td>Branch:<?php echo strtoupper($studentrow['branch']); ?></td></tr>
<tr><td>Semester:<?php echo $studentrow['sem']; ?></td></tr>
</table>
<hr/>
<table>
<tr><td><h4>Book details</h4></td></tr>
<tr><td>isbn:<?php echo $bookrow['isbn']; ?></td></tr>
<tr><td>Book Name:<?php echo strtoupper($bookrow['book_name']);?></td></tr>
</table>
<hr/>
<form action="script/issue.php?isbn=<?php echo $isbn;?>" method='post' id='report'>
<input id="btn_issue" type="button" value="Issue this Book"/>
<input id="btn_close" type="button" value="cancel"/>
</form>
</div>
</body>
</html>
答案 0 :(得分:3)
您需要将属性name
设置为表单中的输入,之后您可以GET
或POST
访问值
改变表格方法:
<form action="script/issue.php?isbn=<?php echo $isbn;?>" method='get' id='report'>
<input name ='isbn' id="btn_issue" type="button" value="Issue this Book"/>
<input name ='eno' id="btn_close" type="button" value="cancel"/>
</form>
或者从帖子中获取变量,例如:
$isbn=$_POST['isbn'];
$eno=$_POST['eno'];
答案 1 :(得分:1)
将您的方法更改为get
<form action="script/issue.php?isbn=<?php echo $isbn;?>" method='get' id='report'>
或者你可以在php中使用$_REQUEST
,它可以读取get
或发布
答案 2 :(得分:0)
如果您使用method="POST"
,则表示您应该使用$_POST
进行下一个过程。也可以使用$_REQUEST
。但我认为$_POST
更具体针对方法POST
。请再次阅读有关表单方法的PHP文档。