我写了这段代码,我确信代码和服务器中的所有东西都是正确的,但它不起作用! 有什么问题?在php中的数据库
<?php
$id = isset($_POST["id"]);
$decrease = isset($_POST["dis"]);
$conn = mysqli_connect('localhost', 'root','');
$select = mysqli_select_db($conn, "test");
if ($decrease=='10%')
$q1 = 'update book set Price=Price-Price * 0.1 where ID="$id";';
else
$q1 = 'update book set Price=Price-Price* 0.3 where ID="$id";';
$b = mysqli_query($conn, $q1);
$query = "select * from book where ID = '$id';";
$res = mysqli_query($conn, $query);
$r = mysqli_fetch_row($res);
print("<table border='1'><tr><td>ID</td><td>Name</td><td>Price</td> </tr>");
echo '<td>'.$r[0].'</td><td>'.$r[1].'</td><td>'.$r[2].'</td>';
?>
不'$ id = isset($ _ POST [“id”]) ;'而是'$ id =(integer)$ _POST [“id”];'这样(1)你不会在'$ id'中得到'isset()'的布尔结果,你防止SQL注入。 – WEBjuju
注意:未定义的索引:C:\ xampp \ htdocs \ Works中的id \第2行的新文本Document.php –
并且在您的查询中将''$ id“'更改为'”'。$ id。'“' 。关于'Notice:Undefined index'的问题是表单发布,如果没有,错误是正确的。因为当没有发布时,没有'$ _POST ['id']'。请学习在php编码和表单处理的基础知识# – JustOnUnderMillions