【发布时间】:2014-01-31 07:26:04
【问题描述】:
我有一个代码,其中我通过表单 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>
【问题讨论】:
-
你的表单方法是
post。将其更改为get -
您正在检查
isset($_POST..,然后尝试从$_GET读取... -
小心。您的代码是对 mysql 注入的调用。
-
正如@HarryFink 已经说过的,您的脚本容易受到SQL 注入的影响;你应该阅读how to prevent them。
-
我知道如何使用 mysqli_real_escape_string 方法来提交数据和防止 sql 注入,但因为这只是示例代码,我没有包含它
标签: php mysql error-handling get