[英]php INSERT statement not working, no echo or error received
In PHP, I am attempting to insert sign up information into a database. 在PHP中,我试图将注册信息插入数据库。 I have worked through a bunch of errors and now I am not getting anything in my window after submitting the form and nothing writes to the database.
我已经解决了很多错误,现在提交表单后窗口什么也没得到,并且没有任何内容写入数据库。 The window comes up blank.
窗口空白。 I have researched answers but have found nothing to assist.
我已经研究了答案,但找不到任何帮助。 I have re-written my VALUES statement several times using various techniques, both trying to use certain code characters and not using them.
我已经使用各种技术多次重写了VALUES语句,试图使用某些代码字符而不使用它们。 Characters include {}, [] and "" as well as ''.
字符包括{},[],“”以及“”。
I have not yet written statements to clean my data, I do realize this will be necessary, I just want to get the script functioning first. 我还没有写声明来清理数据,我确实意识到这是必要的,我只想让脚本首先运行。
The current code for my form resides in one file and my current PHP code resides in a different file which is referenced by the first file. 我表单的当前代码位于一个文件中,而我当前的PHP代码位于另一个文件中,第一个文件引用了该文件。 Here is my current PHP code:
这是我当前的PHP代码:
<?php
if (isset($_POST['submit']))
{
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$user_name = $_POST['user_name'];
$band_name = $_POST['band_name'];
$label_name = $_POST['label_name'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip_code = $_POST['zip_code'];
$email = $_POST['email'];
$confirm_email == ['email'];
$password = $_POST['password'];
$confirm_password == ['$password'];
$dbc = mysqli_connect('localhost', 'root', 'fishstench', 'Site Database.mwb.bak')
or die('Error connecting to MySQL server.');
$query = "INSERT INTO Users (User_ID, First_Name, Last_Name, User_Name, (SHA)Password, Email, Join_Date " .
"VALUES ('{$_POST[First_Name]}','{$_POST[Last_Name]}','{$_POST[User_Name]}','{$_POST[Password]},','{$_POST[Email]}','{$_POST[date]}')";
$query = "INSERT INTO Location (City, State, Zip_Code " .
"VALUES '{$_POST[City]}','{$_POST[State]}','{$_POST[Zip_Code]}')";
$query = "INSERT INTO Band_Name (Band_Name, Label_Name " .
"VALUES '{$_POST[Band_Name]}','{$_POST[Zip_Code]}')";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
mysqli_close($dbc);
echo 'Thanks for signing up!<br />';
} ?>
First, only the last query is gets executed, as you are overwriting the above 2 (I think that's not what you want?). 首先,仅执行最后一个查询,因为您要覆盖上面的两个(我想这不是您想要的吗?)。
Check your $_POST
array if the submit(key)
is set, to pass the check, by using a var_dump
or print_r
just before the check. 通过在检查之前使用
var_dump
或print_r
来检查$_POST
数组是否设置了submit(key)
以通过检查。
if (isset($_POST['submit'])) {
....
}
These lines need to have assignment operator =
, instead of comparison operator ==
, 这些行需要使用赋值运算符
=
,而不是比较运算符==
,
$confirm_email == ['email'];
$confirm_password == ['$password'];
You forgot a closing parenthesis in your first query. 您在第一个查询中忘记了右括号。 I think it should be:
我认为应该是:
$query = "INSERT INTO Users (User_ID, First_Name, Last_Name, User_Name, (SHA)Password, Email, Join_Date) " .
"VALUES ('{$_POST[First_Name]}','{$_POST[Last_Name]}','{$_POST[User_Name]}','{$_POST[Password]},','{$_POST[Email]}','{$_POST[date]}')";
Also, the parentheses in your other queries seem to be incorrect I think they should be: 此外,您在其他查询中的括号似乎不正确,我认为应该是:
$query = "INSERT INTO Location (City, State, Zip_Code) " .
"VALUES ('{$_POST[City]}','{$_POST[State]}','{$_POST[Zip_Code]}')";
$query = "INSERT INTO Band_Name (Band_Name, Label_Name) " .
"VALUES ('{$_POST[Band_Name]}','{$_POST[Zip_Code]}')";
In the future, to detect errors, check the result to see if there is an error: 将来,要检测错误,请检查结果以查看是否存在错误:
$result = mysqli_query($query, $connection);
if (!$result) {
exit("mysqli_query() error: ", mysqli_error($connection), "\nquery was: $query\n");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.