表单数据已正确发布到电子邮件但未正确发布到数据库

时间:2021-12-04 13:26:44

I have a form where people can select whether they have class on the half hour (e.g. starting or end at 12:30, for example) or whether they only classes ending on the whole hour (starting or ending at 1:00pm, for example).

我有一个表格,人们可以选择是否在半小时内上课(例如,开始或在12:30结束),或者他们是否只在整个小时结束的课程(例如,从下午1点开始或结束) )。

This is a checkbox which calls some javascript. When form is submitted, the data is send via POST to a php script that emails the information and also to a php script that inserts the data into a mySQL database.

这是一个调用一些javascript的复选框。提交表单时,数据通过POST发送到php脚本,该脚本通过电子邮件发送信息,也发送到将脚本数据插入mySQL数据库的php脚本。

When the checkbox is checked, i.e. 'Yes', the email that is sent includes the POST field 'Yes' into the email. However, regardless of the selection the database always add a '0' zero to the mySQL column - how can I get it to POST 'Yes' to database when 'Yes' is selected, everything else is working fine.

选中该复选框后,即“是”,发送的电子邮件在邮件中包含POST字段“是”。但是,无论选择什么,数据库总是向mySQL列添加一个“0”零 - 如果选择“是”,我怎样才能将它“发送”到数据库,其他一切正常。

Help is appreciated, code is below :)

感谢帮助,代码如下:)

html form

HTML表单

<input type = "checkbox" name="halfClass" id="halfClass" value="Yes, I have half hour classes." style="width: 50px" onclick = "instructions(true)" >Yes<label style="width: 320px"><strong>Do you have some classes on the half hour?</strong></label></div>

php send email

php发送电子邮件

$halfClass = $_POST['halfClass'];

$message = <<<EOD
<strong>$halfClass</strong> <br> <br />
EOD;

php submit to db

php提交给db

$sql = "INSERT INTO my_awesome_table (halfClass) VALUES ('$halfClass')";

Image: What the Database Table shows :(

图像:数据库表显示的内容:(

3 个解决方案

#1


0  

What is the table's datatype? It might be because the datatype is numeric instead of string. Use varchar to fix if it's not varchar already.

表的数据类型是什么?可能是因为数据类型是数字而不是字符串。如果varchar已经不是varchar,请使用varchar来修复。

#2


0  

Check the datatype of your halfClass column. If it is a numeric type change it to a string type.

检查halfClass列的数据类型。如果是数字类型,则将其更改为字符串类型。

#3


0  

If halfClass is an integer type then use:

如果halfClass是整数类型,那么使用:

$sql = "INSERT INTO my_awesome_table (halfClass) VALUES (".$halfClass.")";

Or if halfClass is of varchar type, then use:

或者如果halfClass是varchar类型,则使用:

$sql = "INSERT INTO my_awesome_table (halfClass) VALUES ('". $halfClass. "')";

#1


0  

What is the table's datatype? It might be because the datatype is numeric instead of string. Use varchar to fix if it's not varchar already.

表的数据类型是什么?可能是因为数据类型是数字而不是字符串。如果varchar已经不是varchar,请使用varchar来修复。

#2


0  

Check the datatype of your halfClass column. If it is a numeric type change it to a string type.

检查halfClass列的数据类型。如果是数字类型,则将其更改为字符串类型。

#3


0  

If halfClass is an integer type then use:

如果halfClass是整数类型,那么使用:

$sql = "INSERT INTO my_awesome_table (halfClass) VALUES (".$halfClass.")";

Or if halfClass is of varchar type, then use:

或者如果halfClass是varchar类型,则使用:

$sql = "INSERT INTO my_awesome_table (halfClass) VALUES ('". $halfClass. "')";