我试图将数据从html表单插入到sql数据库中。当我单击提交时,它应该将表单中的数据放入名为jin的表中,但它没有这样做。我对php和sql非常陌生,所以这可能是一个愚蠢的错误。
<form action="insertform.php" method="post">
Jin Number:<input type="text" name="jin_n"><br>
Jin Name:<input type="text" name="jin_name"><br>
Jin Alt(No Kanji):<input type="text" name="jin_alt"><br>
Number of pages:<input type="text" name="jin_p"><br>
Summary:<input type="text" name="jin_s"><br>
<input type="submit" name="Enter">
</form>
<?php
include "dbconnect.php";
if(isset($_POST['Enter'])){
//
$sqli_code="INSERT INTO jin (JIN_NUM, JIN_NAME, JIN_ALT`, JIN_PGS, JIN_SUM) VALUES(
NUL,
'$_POST[jin_name]',
'$_POST[jin_alt]',
'$_POST[jin_p]',
'$_POST[jin_s]')";
echo "<br><br><br> SQLI_CODE: ", $sqli_code;
mysqli_query($dbconnect,$sqli_code);
};
?>
//dbconnect.php
<?php
$dbconnect = mysqli_connect("localhost","root","","nururu");
if(mysqli_connect_errno())
{
echo 'Connection Error' .msqli_connect_error();
exit;
}
?>
答案 0 :(得分:1)
变化
(JIN_NUM, JIN_NAME, JIN_ALT`, JIN_PGS, JIN_SUM)
到
(JIN_NUM, JIN_NAME, JIN_ALT, JIN_PGS, JIN_SUM)
你可以看到一个&#39;额外的。
和NUL
?我希望你的意思是NULL
答案 1 :(得分:0)
代码中有些愚蠢的错误。这段代码可以帮助你。
<?php
include "dbconnect.php";
if(isset($_POST['Enter'])){
$sqli_code="INSERT INTO jin (JIN_NUM, JIN_NAME, JIN_ALT, JIN_PGS, JIN_SUM) VALUES(
'',
'$_POST[jin_name]',
'$_POST[jin_alt]',
'$_POST[jin_p]',
'$_POST[jin_s]')";
echo "<br><br><br> SQLI_CODE: ", $sqli_code;
mysqli_query($dbconnect,$sqli_code);
};
?>