-1

大家好,我有这样的代码

include('db.php');

if (isset($_POST['save']) && $_POST['save'] == '') {

    if(isset($_POST['misamarti'])){ $misamarti = $_POST['misamarti']; }
    if(isset($_POST['teleponi'])) { $teleponi = $_POST['teleponi']; }
    if(isset($_POST['posta'])) { $posta = $_POST['posta']; }
    if(isset($_POST['paqsi'])) { $paqsi = $_POST['paqsi'];}


    $query = "UPDATE contact SET  `misamarti` =  ".$misamarti.", `teleponi` =  ".$teleponi.", `posta` =  ".$posta.", `paqsi` =  ".$paqsi." WHERE  `contact`.`id` =1;";
    $result = mysql_query($query);

}

<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="about" value="template1" />
<input type="text" value="" name"misamarti" />
<input type="text" value="" name"teleponi" />
<input type="text" value="" name"posta" />
<input type="text" value="" name"paqsi" />
<input type="submit" value="" name="save" /> 

结果是

注意:未定义变量:第 18 行 C:\xampp\htdocs\Template\admin_panel\contact.php 中的
misamarti 注意:未定义变量:第 18 行 C:\xampp\htdocs\Template\admin_panel\contact.php 中的 teleponi
注意:未定义变量:第 18 行 C:\xampp\htdocs\Template\admin_panel\contact.php 中的 posta
注意:未定义变量:第 18 行 C:\xampp\htdocs\Template\admin_panel\contact.php 中的 paqsi

如果有人知道为什么会出现此错误,请发表评论。

4

2 回答 2

0

即使它们没有与表单一起提交,您也正在使用这些变量,并使用这些未定义的变量更新数据库中的字段,因此您将破坏以前在数据库中的任何数据。

如果不出意外,您至少需要为字段设置默认值,例如:

 $misamarti = isset($_POST['misamarti']) ? $_POST['misamarti'] : '';
                                                                 ^^--default empty string

然后意识到你对sql 注入攻击很开放。您正在乞求获得您的服务器 pwn3d。

于 2013-06-04T18:35:45.993 回答
0

正如您在 HTML 代码中看到的那样,您的名称写得不好,它们必须这样写:name="misamarti". 您忘记了和名称=之间的等号 ( ) 。name如果您看到其余的属性,例如textand value,您会看到有一个相等的,这是设置属性的正确方法。

于 2013-06-05T08:45:53.590 回答