This question already has answers here:
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
                                
                                    (28个答案)
                                
                        
                                4年前关闭。
            
                    
我有一个基本问题。我有一个简单的表(仅1个字段-nama)和1个使用php的简单页面。我可以将数据插入表“ userad”。但是,当我添加几个字段,例如id,name2,color2和hobby2时,mysql经常返回空结果。 id是整数NOT NULL,也不会自动递增。我不确定是什么问题。我已经在Internet上浏览了解决方案,但是找不到并理解解决该问题的方法。请帮助... tq ..

下面是单个数据的PHP脚本-能够显示数据的mysql。

<?php
// Start the session.

session_start();

require 'connect-test.php';

  if(isset($_POST['nama']))

   {  $nama = $_POST['nama'];

    $stmt = $conn->prepare("INSERT INTO userad (nama) VALUES (?)");
    $stmt->bind_param("s", $nama);
    $stmt->execute();

    $stmt->close();
    $conn->close();   }

  ?>

<html>
<head> </head>
<body>

<form name="form2" method="post" action="testdelete2.php">

          <p>nama :
          <input type="text" name="nama" id="nama">

        </p>
    <p>
    <input type="submit" name="button" id="button" value="Submit">
  </p>

      </form>
      </body>
               </html>


以下是用于多个数据的php脚本-mysql不断返回空结果(错误)

<?php
// Start the session.

session_start();

require 'connect-test.php';

 if(isset($_POST['submit']))

   {
    $id = $_POST['id'];
    $name2 = $_POST['name2'];
    $color2 = $_POST['color2'];
    $hobby2 = $_POST['hobby2'];



    $stmt = $conn->prepare("INSERT INTO userad (id,name2,color2,hobby2) VALUES (?,?,?,?)");
    $stmt->bind_param("isss",$id,$name2,$color2,$hobby2);
    $stmt->execute();

    $stmt->close();
    $conn->close();}

<html>
<head> </head>
<body>

<form name="form2" method="post" action="testdelete2.php">

          <p>id:
          <input type="text" name="id" id="id">

        </p>
 <p>name2:
          <input type="text" name="name2" id="name2">

        </p>
 <p>color2:
          <input type="text" name="color2" id="color2">

        </p>
 <p>hobby2:
          <input type="text" name="hobby2" id="hobby2">

        </p>
    <p>
    <input type="submit" name="button" id="button" value="Submit">
  </p>

      </form>
      </body>
               </html>

最佳答案

<input type="submit" name="submit" id="button" value="Submit">


使用此输入类型以表格形式提交并检查

关于php - mysql不断返回空结果(错误),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34451600/

10-10 14:04
查看更多