所以$ _POST [' acc']和$ _POST [' psw']由于某种原因无法从表单中获取数据,因此它们始终为空
HTML:
<div id="signUp_UI">
<form id="su_form" action="<?php echo url_for('/sign_up.php')?>" method="post" enctype="multipart/form-data">
YYQ<br><br>
Account Name<br>
<input type="text" placeholder="Account Name" id="an" name="acc">
<br><br>
Passward<br>
<input type="password" placeholder="Password" id="password" name="psw">
<br><br>
<input type="button" name="goback" value="Go Back" id="gb_button">
<input type="submit" value="Sign Up" id="su_button2">
</form>
</div>
PHP:
$an = isset($_POST['acc']) ? $_POST['acc'] : '';
$psw = isset($_POST['psw']) ? $_POST['psw'] : '';
$sql = "INSERT INTO log_in (account, password) VALUES ('". $an . "'," . "'" . $psw . "')";
$result = mysqli_query($db, $sql);
if($result){
$new_id = mysqli_insert_id($db);
redirect_to(url_for('/home.php?id=') . $new_id);
}
else{
echo mysqli_error($db);
db_disconnect($db);
exit();
}
更新
所以,如果我将PHP代码更改为:
if(is_post_request()){
$an = isset($_POST['acc']) ? $_POST['acc'] : '';
$psw = isset($_POST['psw']) ? $_POST['psw'] : '';
$sql = "INSERT INTO log_in (account, password) VALUES ('". h($an) . "'," . "'" . h($psw) . "');";
$result = mysqli_query($db, $sql);
if($result){
echo '$an = ' . $an .'<br>';
echo '$psw = ' . $psw;
}
else{
echo mysqli_error($db);
db_disconnect($db);
exit();
}
然后我得到了结果: $ an = $ psw =
更新:
所以我试图在php文件中检测isset($_POST['submit'])
,结果是$ _POST [&#39;提交&#39;]不存在。
因此,在我提交表单之后,由于某种原因,它还没有被发送到php文件。
更新3.0:
所以,如果我改变方法来获取,一切都可以找到!我不知道为什么会这样。
HTML:
<div id="signUp_UI">
<form id="su_form" action="<?php echo url_for('/sign_up.php'); ?>" method="get">
YYQ GameStation<br><br>
Account Name<br>
<input type="text" placeholder="Account Name" id="an" name="account">
<br><br>
Password<br>
<input type="password" placeholder="Password" id="password" name="password">
<br><br>
<input type="button" name="goback" value="Go Back" id="gb_button">
<input type="submit" name = "submit" value="Sign Up" id="su_button2">
</form>
</div>
PHP:
if(isset($_GET['submit']) && !empty($_GET['submit'])){
$an = isset($_GET['account'])?$_GET['account']:'';
$psw = isset($_GET['password'])?$_GET['password']:'';
$sql = "INSERT INTO log_in (account, password) VALUES ('". h($an) . "'," . "'" . h($psw) . "');";
$result = mysqli_query($db, $sql);
if($result){
redirect_to(url_for('/home.php'));
}
else{
echo mysqli_error($db);
db_disconnect($db);
exit();
}
答案 0 :(得分:1)
好吧,根据我发现的消息来源,似乎phpstrom内置服务器出了问题。 POST方法不知何故不起作用。
答案 1 :(得分:-2)
为什么你需要这样做?
<form id="su_form" action="<?php echo url_for('/sign_up.php')?>" method="post" enctype="multipart/form-data">
您可以尝试替换此
从:
action="<?php echo url_for('/sign_up.php')?>"
为:
action="sign_up.php"