dtnqbre7980007 2012-01-02 20:58
浏览 63
已采纳

PHP注册码不起作用

The code below is meant to insert values into a MySQL Database if the passwords match, the username or email isn't used already. This code is called from ajax on another page. When it is called, the page redirects me to register.php instead of being completed on the backend by ajax. Does anybody see any issues that could be causing this? It doesn't give me any errors, just a blank white page.

$user = strip_tags(htmlspecialchars($_POST['user'], ENT_QUOTES));
$pass = strip_tags(htmlspecialchars($_POST['pass'], ENT_QUOTES));
$cpass = strip_tags(htmlspecialchars($_POST['cpass'], ENT_QUOTES));
$age = strip_tags(htmlspecialchars($_POST['age'], ENT_QUOTES));
$email = strip_tags(htmlspecialchars($_POST['email'], ENT_QUOTES));
$country = strip_tags(htmlspecialchars($_POST['count'], ENT_QUOTES));
$lang = strip_tags(htmlspecialchars($_POST['lang'], ENT_QUOTES));
$mdpass = md5($pass);
$mdcpass = md5($cpass);
$created = Date("Y-m-d");


$result = mysql_query("SELECT username,email FROM tableName WHERE username = '$user'");
while ($row = mysql_fetch_array($result)) 
{
if ($row['username']>0) {
    echo 'nvuname';
} 
elseif ($row['email']>0)
{
    echo 'nvemail';
}
else
{
    if ($mdpass == $mdcpass && $age>>14) 
    {
        mysql_query("INSERT INTO tableName (username, pword, email,created,admin,rnumenab,autoreload,country,mailenab,updates,lang) VALUES ($user, $mdpass, $email, $created,'0','1','1',$country,'1','0',$lang)");
        echo 'success';
    }
}

JavaScript:

$("#regsubmit").click(function() {
    var action = $("#mainReg").attr('action');
    var form_data = {
        user: $("#user-reg").val(),
        pass: $("#pass-reg").val(),
        cpass: $("#cpass-reg").val(),
        email: $("#email").val(),
        age: $("#age").val()
    };
    $.ajax({
        type: "POST",
        url: action,
        data: form_data,
        success: function(result)
        {
            if(result=='success') {
                $('#register-action').animate({
                    opacity : '-=1',
                    bottom : '-=60%'
                    }, 600);
                $('#register-action-bckgnd').hide();
                $('.message').fadeOut(600);
            } else {
                $('.regerror').fadeIn(600);
            }
        }
    });
    return false;
});

Thanks, and if you see any issues please let me know. Thank you so much!

Also:How do I sanitize my inputs so no HTML tags are included or did the strip_tags do that? Thanks.

EDIT: It now works and submits the page doesn't reload, but it always returns error instead of success even if I am sure I am using an open email, username. Turns out I had ('$age') instead of ('#age'). Ideas?

  • 写回答

2条回答 默认 最新

  • doudi4137 2012-01-02 21:05
    关注

    Although I have not seen your javascript, when an ajax call results in a blank page, that normally means the page is being posted normally and not (only...) by ajax.

    You will need to add something like

    event.preventDefault();
    

    or

    return false;
    

    to your javascript click / submit function.

    Edit: Without seeing the html, you are using a click-handler and although that click-handler may return false, that does not mean that the form does not get submitted normally. I would attach the javascript to the form submit-handler instead and prevent the submit.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题