SQL查询突然无法通过PHP工作

时间:2017-08-24 19:44:06

标签: php html mysql forms

我有一个HTML表单,希望它的输出插入到我的(本地)mysql中。 但是,在它成功一次之后,当我提交表单并且我没有更改代码时,它突然不再起作用了。现在我只看到一个空白页面,其中包含网络选项卡中的发布请求。怎么没有插入任何东西?

的script.php:

<?php
$postdata = file_get_contents("php://input");
$link = mysqli_connect("127.0.0.1", "root", "", "izandb");

if(isset($_POST['submit'])) {
$klas = $_POST['klasDown'];
$naam = $_POST['naamTxt'];

$stmt = $link->prepare('INSERT INTO resultaten (Klas, Naam, Percentages, 
Antwoorden)  VALUES (?, ?, ?, ?)');
$stmt->bind_param('ssss', $klas, $naam, $klas, $klas);
$stmt->execute();
echo "Insertion succeed";
} else {
echo "Insertion not succeed";
}
?>

html表格:

<form id="myForm" method="post" action="script.php">
Volledige naam: <input name="naamTxt" type="text" maxlength="512" id="naamTxt" 
 class="searchField"/> <br>
 Klas: <select name="klasDown">
  <option value="H4A" selected="selected">H4A</option>
  <option value="H4B" >H4B</option>
  <option value="H4C">H4C</option>
  <option value="H4C">H4D</option>
  <option value="H4C">V4A</option>
  <option value="H4C">V4B</option>
  <option value="H4C">V4C</option>
  <option value="H4C">V4D</option>

</select> 
</div>


<div class="row">
<div class="col-4">1. Ik ben spontaan. </div>
<div class="col text-center"><input type="radio" name="v1" id="v1_1" 
value="Helemaal mee oneens"></div>
<div class="col text-center"><input type="radio" name="v1" id="v1_2" 
value="Deels oneens"></div> 
<div class="col text-center"><input type="radio" name="v1" id="v1_3" 
value="Neutraal"></div> 
<div class="col text-center"><input type="radio" name="v1" id="v1_4" 
value="Deels mee eens"></div> 
<div class="col text-center"><input type="radio" name="v1" id="v1_5" 
value="Helemaal mee eens"></div>
</div>

<br> <input type="submit" name="submit" value="submit" onsubmit="bereken()"></input>

2 个答案:

答案 0 :(得分:0)

请务必关闭代码。

    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
   }
   echo "<pre>";
   print_r($_POST);

插入此代码并找到错误

答案 1 :(得分:0)

好的,所以在与你交谈并重现场景之后,我能够稍微修改一下脚本,然后想出一些对我有用的东西。

$result = array();
$i = 0;

#$rows - data from the database
foreach($res as $rows){
    $result[$i] = ['aa' => 'bb', 'cc' => 'dd', 'ee' => 'ff'];
    array_push($result[$i], ['gg' => 'hh', 'ii' => 'jj']);

    $i++;
}

#The expected result:
#Array('aa' => 'bb', 'cc' => 'dd', 'ee' => 'ff', 'gg' => 'hh', 'ii' => 'jj');

#Reality:
#Array(0 => ['gg' => 'hh', 'ii' => 'jj'], 'aa' => 'bb', 'cc' => 'dd', 'ee' => 'ff');