[英]Sql query suddenly doesnt work through php
I have a HTML-form and want the output of it inserted in my (local) mysql. 我有一个HTML表单,并希望将其输出插入到我的(本地)mysql中。 However, after it succeeded once, it suddenly doesnt work anymore when I submit the form and I havent changed the code.
但是,一次成功后,当我提交表单并且没有更改代码时,它突然不再起作用。 Now I just see a blank page with the Post-request in Network tab.
现在,我只看到一个空白页面,其中包含“网络”选项卡中的“后请求”。 How does it come nothing is inserted anymore?
怎么没有东西插入了呢?
script.php: 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: 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>
Please make sure to close the in your code. 请确保关闭代码中的。
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
echo "<pre>";
print_r($_POST);
insert this code and find the error 插入此代码并找到错误
Okay, so after talking to you and reproducing the scenario, I was able to modify the script a bit and come up with something which worked fine for me. 好的,在与您交谈并重现了场景之后,我可以稍稍修改脚本并提出一些对我来说很好的方法。
<?php
$postdata = file_get_contents("php://input");
mysqli_report(MYSQLI_REPORT_ALL);
try
{
$link = new mysqli( 'localhost', 'test_account', 'test_password', 'database');
}
catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
if(isset($_POST['submit'])) {
$klas = $_POST['klasDown'];
$naam = $_POST['naamTxt'];
$query = 'INSERT INTO resultaten (Klas, Naam, Percentages, Antwoorden) VALUES (?, ?, ?, ?)';
if ($stmt = $link->prepare( $query ))
{
$stmt->bind_param('ssss', $klas, $naam, $klas, $klas);
$stmt->execute();
$stmt->close();
echo "Insertion succeed";
} else {
echo "Insertion not succeed";
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.