【发布时间】:2015-09-27 14:10:03
【问题描述】:
错误似乎是这样的:
注意:未定义索引:第 32 行 C:\wamp\www\job.php 中的 JobID 第 32 行是:$JobID=$_GET['JobID'];
我试图解决这个问题 10 天,阅读不同作者的不同书籍。但是我还是不知道哪里出错了。
<?php
if(isset($_POST["submit"])) //this is form action
{
$result3 = mysql_query("SELECT * FROM members where user='$user'");
while($row3 = mysql_fetch_array($result3))
{
$name=$row3['name'];
$user=$row3['user'];
$number=$row3['number'];
}
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO applicant (user,name,number,) VALUES('$user','$name','$number')";
$result=mysql_query($sql);
if($result){
header('Location: thankyou2.php');
} else {
echo "Failure!";
}
}
}
else
{
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "abcdef";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
$JobID=$_GET['JobID'];
$job_sql="SELECT * FROM job WHERE JobID=$JobID";
$job_query = mysql_query($job_sql) or die(mysql_error());
$rsjob=mysql_fetch_assoc($job_query);
};
?>
<b><center><table class="bordered">
//Data will fetch in this table by GET method
<thead>
<?php echo $rsjob['jobname'];?></h1></font>
<tr>
<th><font face="Script MT">Description</th>
<th><font face="Script MT">Details</th>
</tr>
</thead>
<tr>
<td>Name</td>
<td><?php echo $rsjob['jobname'];?></td>
</tr>
<tr>
<td>Type</a></td>
<td><?php echo $rsjob['type'];?></td>
</tr>
</table><br>
<?php
if ($loggedin)
{
echo
<<<_END
<form action="job.php" method="POST" name="jobapply">
<input type="checkbox" name="termscondition" required/> I have read all the
<a href="termscondition.html">Terms and Condition</a><br>
<br><input type="submit" value="Apply"></form>
_END;
}
else
{
echo '<center> please sign up and/or log in to <strong>Apply</strong>. </center>';
};
?>
【问题讨论】:
-
您是否在 URI 中添加了 ?JobID=1234?
-
您将发布多少个相同的问题? stackoverflow.com/questions/31240873/…努力学习
-
JobID='$JobID'应该解决查询错误并添加检查。 -
你的代码有很多SQL注入漏洞,如果你把这段代码放到网上很可能会被利用。您可以通过将包含数字的字符串转换为整数或使用
mysql_real_escape_string()来解决此问题,但最好切换到支持参数化的数据库库。无论如何,您目前使用的库现在已被弃用。
标签: php mysql phpmyadmin get localhost