douke9379 2017-11-08 02:40
浏览 66

$ _POST []数组在提交后为空

So $_POST['acc'], and $_POST['psw'] can't get data from the form for some reason, they are empty all the time.

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();
}

Update:

So if I change php code to:

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();
}

then I got the result: $an = $psw =

UPDATE:

So I tried to detect isset($_POST['submit']) in php file, the result is $_POST['submit'] does not exist.

So it's like after I've submit the form, it isn't been sent to the php file for some reason.

UPDATE 3.0:

So if i change method to get, everything works find! I don't know why is that.

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();
}
  • 写回答

2条回答 默认 最新

  • douchuilai2355 2017-11-08 03:17
    关注

    Why you need to do this?

    <form id="su_form" action="<?php echo url_for('/sign_up.php')?>" method="post" enctype="multipart/form-data">
    

    Can you try to replace this

    from:

    action="<?php echo url_for('/sign_up.php')?>"
    

    to:

    action="sign_up.php"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画