简体   繁体   English

无法获取表单数据以发布到SQL(使用MySQL 5.5.25)

[英]Cannot get form data to post to SQL (using MySQL 5.5.25)

I'm working on a project and I'm having a bit of trouble getting my form data to post to my SQL database. 我正在做一个项目,但在将表单数据发布到SQL数据库时遇到了一些麻烦。 At first the auto inc ID values were working any time I'd submit the form, but no other data would post... now nothing at all happens... I'm very rusty with php... anyways here is what I have so far. 起初,auto inc ID值在我提交表单的任何时间都有效,但是没有其他数据可以发布...现在什么也没有发生...我对php非常生锈...无论如何,这就是我的目的到目前为止。

insert.php insert.php

<?php
include ("connect.php");
$sql = "INSERT INTO 'tc_db'.'teamchiefs' ('lastname',  'firstname','unit','datecert','initial')
VALUES ('$_POST[lastname]','$_POST[firstname]','$_POST[unit]','$_POST[datecert]')";
if (!mysqli_query($con,$sql))
{
die('Error:' . mysqli_error(@con));
}
echo "Record Added";
mysqli_close($con);
?>

And my form.html file... clipped down to save space. 还有我的form.html文件...已缩减以节省空间。

<body>
<ul>

<form action="insert.php" method="post">
"sprytextfield1">
<label>Last Name:
  <input type="text" name="lastname" id="lastname" />
</label>
<label>First Name:
    <input type="text" name="firstname" id="firstname" />
  </label>
<label>Middle Initial
  <input name="initial" type="text" id="initial" size="5" maxlength="1" />
</label>

...etc

//spry widget javascript stuff here

</form>
</ul>
</div>
</body>

My sql tables are 我的SQL表是

ID - BIGINT(20) - A_I
lastname - VARCHAR(60)
firstname - VARCHAR(60)
unit - VARCHAR(6)
datecert - YEAR(4)
initial - VARCHAR(1)

I appreciate any help. 感谢您的帮助。

INSERT INTO 'tc_db'.'teamchiefs'

对表和列名称使用反引号

INSERT INTO `tc_db`.`teamchiefs` 

You have declared that you're inserting into five columns ('lastname', 'firstname','unit','datecert','initial') but you're only providing four values ('$_POST[lastname]','$_POST[firstname]','$_POST[unit]','$_POST[datecert]') . 您已经声明要插入五列('lastname', 'firstname','unit','datecert','initial')但只提供了四个值('$_POST[lastname]','$_POST[firstname]','$_POST[unit]','$_POST[datecert]') Looks like you're missing a value for initial . 看起来您缺少initial的值。 That's will cause your query to fail. 这将导致您的查询失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM