gpt4 book ai didi

php - 使用 GET 和 POST 在 PHP 中 undefined index

转载 作者:太空宇宙 更新时间:2023-11-03 11:08:12 25 4
gpt4 key购买 nike

我有一个 php 文件 p1.php,它从另一个 php 文件 p2.php 中获取数据,该文件在 p1.php 中通过 $_GET 访问。现在 $_GET 中的数据被保存在变量 $totPrice 中。 p1.php 也有一个引用自身的表单,一些处理是用 MySql 数据库完成的。我收到以下错误:

"Notice: Undefined index: totP in C:\xampp\htdocs\fi\p1.php on line 'where ever $totPrice appears'".

这是 p1.php 的代码:-

<?php
global $totPrice;
$totPrice = $_GET['totP'];
if(!isset($_COOKIE['username']))
{
if(isset($_POST['Submit']))
{
$dbc = mysqli_connect("localhost","root","","authserver");
$username = $_POST['name'];
$password = $_POST['password'];
$ccno = $_POST['ccno'];

if(!empty($username) && !empty($password) && !empty($ccno))
{
$query = "select * from authserver.fimembers where fName = '$username' AND password_finmem=SHA('$password') AND CreditCard = $ccno";
$result = mysqli_query($dbc,$query);

if(mysqli_num_rows($result) == 1 )
{
$dbc1 = mysqli_connect("localhost","root","","fininsti");
$query1 = "select * from fininsti.fimembers where fName = '$username' AND password_finmem=SHA('$password') AND CreditCard = $ccno";
$result1 = mysqli_query($dbc1,$query1);
$row = mysqli_fetch_array($result1,MYSQL_BOTH);
setcookie('username',$username,time()+60*60);
setcookie('ccno',$row[0],time()+60*60);
echo $totPrice.'<br />';
if($totPrice > $row[3])
if($_GET['totP'] > $row[3])
{
$status = array('stat' => 0 ); // 0 = Not sufficient funds
}
else
{
$status = array('stat' => 1 ); // 1 = Good To Go!
$newAmt = $row[3]-$totPrice;
$query = "update fininsti.fimembers set Credit = $newAmt where CreditCard = $ccno";
$result = mysqli_query($dbc1,$query);
}
$retMerUrl = "http://localhost/eTrans/site/confirm.php?".http_build_query($status);
setcookie('username',$username,time()-60*60);
setcookie('ccno',$row[0],time()-60*60);
mysqli_close($dbc1);
mysqli_close($dbc);
header('Location:'.$retMerUrl);
}
else
echo "Credentials don't match!";
}
else
{
echo "Sorry! Fields empty!";
}
setcookie('userId',$username,time()-60*60);
setcookie('ccno',$row[0],time()-60*60);
mysqli_close($dbc);
}
}
?>

如果您对这个问题有任何疑问,请务必回复我。

最佳答案

您需要修复前两行:

global $totPrice;
$totPrice = $_GET['totP'];
  1. 删除第一行。在函数之外不需要 global
  2. 将第二行替换为:

    $totPrice = isset($_GET['totP']) ? $_GET['totP'] : 0;
  3. (与这两行无关)修复代码中的 SQL 注入(inject)问题!!!

关于php - 使用 GET 和 POST 在 PHP 中 undefined index ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10421154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com