【问题标题】:What's the error and how to solve this in PHP 7.4? [duplicate]PHP 7.4 中有什么错误以及如何解决这个问题? [复制]
【发布时间】:2020-08-30 20:52:42
【问题描述】:

我尝试使用 MySQL 和 PHP 在我的网站上创建一个表单,但它没有在数据库中保存任何内容,但来自网站的视图并没有出现错误。什么是错误以及如何解决它,所以我希望你能解决这个问题。 我认为错误是在执行中,但我不确定 a 并且我无法解决它。

$dcuser = $_POST["user"];
$tmpuser = $_POST["tmpuser"];
$spedi = $_POST["spedi"];
$selecte = $_POST["selecte"];
$data = $_POST["data"];
$save = $_POST["save"];

$test2 = [$dcuser, $tmpuser, $spedi, $selecte, $data, $save];

if (!isset($dcuser)) {
   echo("test");
}
else{
   if (!isset($tmpuser)) {
       echo("test");
   }
   else {
       if (!isset($spedi)) {
           echo("test");
       }
       else {
           if (!isset($selecte)) {
               echo("test");
           }
           else {
               if (!isset($data)) {
                   echo("test");
               }
               else {
                   if (!isset($save)) {
                       echo("test");
                   }
                   else {
                       echo($test2->a);
                   }
               }
           }
       }
   }
}

$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'user';
$DATABASE_PASS = 'pw';
$DATABASE_NAME = 'form';

$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);

$test[] = $_POST['user'];
$test[] = $_POST['tmpuser'];
$test[] = $_POST['spedi'];
$test[] = $_POST['selecte'];
$test[] = $_POST['data'];
$test[] = $_POST['save'];

$statement = $con->prepare("INSERT INTO konvoi (user, tmpuser, spedi, selecte, daten, save) VALUES (?, ?, ?, ?, ?, ?)");
$statement->execute(array($test[0], $test[1], $test[2], $test[3], $test[4], $test[5]));

if(isset($dcuser)) {
 if(isset($tmpuser)) {
   if(isset($spedi)) {
     if(isset($selecte)) {
       if(isset($data)) {
         if(isset($save)) {
           echo '<p>User: '.$test[0].'</p>';
           echo '<p>TMP: '.$test[1].'</p>';
           echo '<p>Spedi: '.$test[2].'</p>';
           echo '<p>selecte: '.$test[3].'</p>';
           echo '<p>Data: '.$test[4].'</p>';
           echo '<p>Save: '.$test[5].'</p>';
         }  else {
           echo 'test6';
         }
       }  else {
         echo 'test5';
       }
     }  else {
       echo 'test4';
     }
   }  else {
     echo 'test3';
   }
 }  else {
   echo 'test2';
 }
} else {
 echo 'test1';
} 

HTML:

  <form action="convoi.php" method="post">
        <input class="input" type="text" placeholder="Discord Username" name="user" required>
        <br>
        <input class="input" type="text" placeholder="TMP Username" name="tmpuser" required>
        <br>
        <input class="input" type="text" placeholder="Spedition" name="spedi" required>
        <br>
        <label class="frage">Wie hast du von dem Konvoi erfahren?:
          <br>
          <select name = "selecte" class="option" required>
                <option>Eigene Spedition</option>
                <option>Anderer Spedition</option>
                <option>Unsere Internetseite</option>
                <option>Werbung von einem Spieler</option>
            <option>Sonstiges</option>
            <option>Keine Angabe</option>
            </select>
        </label>
          <br>
        <p class="datenschutz"><input type="checkbox" name="data" required>Ich aktzeptiere die <a class="data" href="https://otendex.de/datenschutz/#">Datenschutzbestimmungen </a></p>
        <p class="datenschutz"><input type="checkbox" name="save" required> Ich stimme zu das meine Daten gespeichert werden</p>
        </input>
        <div class="h-captcha" style="text-align: center"data-sitekey="22995024-4ceb-4169-a763-d81020ed4eea"></div>
        <button class="button" type="submit" value="Absenden">
          Absenden
        </button>
      </form>```

【问题讨论】:

  • $statement-&gt;execute(array($test[0], $test[1], $test[2], $test[3], $test[4], $test[5])) $statement->execute($test);
  • 看这里的问题echo($test2-&gt;a);
  • 你的解决方案后同样的问题
  • 我测试了你的代码并且正在移除这个 echo($test2->a);并更改

标签: php mysql forms


【解决方案1】:

你尝试过使用

   echo $statement->execute

在$statement->执行之后。如果是 db 错误,它会在屏幕上打印出来吗?

【讨论】:

  • 它什么也不打印
猜你喜欢
  • 2021-01-10
  • 2021-06-25
  • 1970-01-01
  • 2016-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-24
  • 2015-06-13
相关资源
最近更新 更多