dqyin0101 2016-11-19 06:09
浏览 83
已采纳

接收POST的失败导致PHP / HTML

I've done tests and it's definitely not a problem with the database, it connects fine and variables input if specified, (the integers work). Note that the {} brackets around the variables in the sql statement, for some reason need to be there for it to work, if someone could tell me why that'd be great.

The main problem is the POST for receiving from the form, nothing echoes, nor inputs to the database. Can anyone help? Thanks in advance.

PHP:

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
$pw = $_POST['pw'];
$email = $_POST['email'];
$wins = 0;
$losses = 0;
$played = 0;
$earnings = 0;

$sql = "
INSERT INTO users (first_name, last_name, username, password, email, last_login, date_joined, wins, losses, played, earnings) VALUES
('{$firstName}','{$lastName}','{$username}','{$pw}','{$email}','1111','2222','{$wins}','{$losses}','{$played}','{$earnings}')
";

if(!mysql_query($sql, $con)){
echo 'Worked';
} else {echo 'Failed';}

HTML:

<form id="registration_form" action="http://valhq.com/register/" method="POST"> 
<div class="signup_form_content_names">
    <div class="signup_form_input_fn">
        <input type="text" class="signup_input_style_fn" id="firstName" placeholder="First Name" maxlength="20">
    </div>
    <div class="signup_form_input_ln">
        <input type="text" class="signup_input_style_ln" id="lastName" placeholder="Last Name" maxlength="20">
    </div>
</div>
<div class="signup_form_content">
    <div class="signup_form_input">
        <input type="text" class="signup_input_style" placeholder="E-Mail" id="email" maxlength="40">
    </div>
    <div class="signup_form_input">
        <input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" maxlength="40">
    </div>
    <div class="signup_form_input">
        <input type="text" class="signup_input_style" placeholder="Desired Username" id="username" maxlength="20">
    </div>
    <div class="signup_form_input">
        <input type="password" class="signup_input_style" placeholder="Password" id="pw" maxlength="64">
    </div>
    <div class="signup_form_input">
        <input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" maxlength="64">
    </div>
    <div class="signup_tc">
        <p>
            <input type="checkbox" id="terms" value="terms_true" style="vertical-align:middle;">
            I agree to the <a href="http://valhq.com/terms">Terms and Conditions</a>
            <span class="signup_tc_required">*</span>
        </p>
    </div>
    <input type="submit" id="submit" class="signup_submit" value="Create Account">
    <div class="signup_alreadyMember">
        <a href="http://valhq.com/login">Already a member? Login.</a>
    </div>
    <div class="signup_error">
        <span class="signup_error" id="fn_error_message"></span>
        <span class="signup_error" id="ln_error_message"></span>
        <span class="signup_error" id="email_error_message"></span>
        <span class="signup_error" id="emailconf_error_message"></span>
        <span class="signup_error" id="username_error_message"></span>
        <span class="signup_error" id="pw_error_message"></span>
        <span class="signup_error" id="pwconf_error_message"></span>
        <span class="signup_error" id="tos_error_message"></span>
    </div>
</div>
</form>
  • 写回答

4条回答 默认 最新

  • dongsun5330 2016-11-19 06:15
    关注

    if you want to get your values using $_POST your inputs name attributes must be set

    example add name="firstName"

    <input type="text" class="signup_input_style_fn" name="firstName"  id="firstName" placeholder="First Name" maxlength="20">
    

    So now you can access it using

    $firstName = $_POST['firstName'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助