-2

I tried to make a form on my Website with MySQL and PHP but it doesn't save anything in the Database, but the view from the Website isn't like there is an error. What's the error and how to solve it, so I hope, you can solve this. I think the error is in execute but I'm not sure a and I couldn't solve it.

$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>```
M--
  • 25,431
  • 8
  • 61
  • 93
SuperDog
  • 1
  • 1

1 Answers1

-2

Did you tried using

   echo $statement->execute

after $statement->execute. If it's db error it will print that on screen?