无法将数据插入数据库 [英] cant insert data to database

查看:84
本文介绍了无法将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友



我设计了一个注册页面,但是我无法将数据插入数据库我使用了php脚本的ajax机制!请给我解决方案我无法在我的代码中找到错误

ajaxresponseText返回注册成功但没有数据插入数据库

hi friends

I have design a signup page but i cant insert data to database I used ajax mechanism with php script!! pls give me solution i cant find error in my code
ajaxresponseText returns "signup success" but no data inserts database

<?php
//Ajax calls this registration code to execute
if(isset($_POST["u"])){
        //CONNECT TO THE DATABASE
        include_once("db_conx.php");
//GATHER THE POSTED DATA INTO LOCAL VARIALES

$u = preg_replace('#[^a-z0-9]#i','',$_POST['u']);
$e = mysqli_real_escape_string($db_conx,$_POST['e']);
$p = $_POST['p'];
$g = preg_replace('#[^a-z]#','',$_POST['g']);
$c = preg_replace('#[^a-z}]#','',$_POST['c']);

//Get user Ip
$ip = preg_replace('#[^1-9.]#','', getenv('REMOTE ADDR'));
//Duplicate data checks for username and email
$sql = "SELECT id FROM users WHERE username='$u'LIMIT 1";
if ($u_check = mysqli_query($db_conx,$sql))
{
     mysqli_num_rows($u_check);
}

//---------------------------------------------
$sql = "SELECT id FROM users WHERE email='$e' LIMIT 1";

if($e_check = mysqli_query($db_conx,$sql))
{
         mysqli_num_rows($e_check);
}
//From Data Error Handling

if($u== ""|| $e == "" || $p == "" || $g == ""  || $c == "")
{

echo "The form submission is missing values.";
exit();
}
else if ($u_check > 0)
{
echo " The username you entered is already taken";
exit();
}
else if ($e_check > 0)

{
echo "Email Address is already in use";

exit();
}
else if(strlen($u)< 3 || strlen($u) > 16)
{
 echo " username must be between 3 and 16 characters";
exit();

}
    else if(is_numeric($u[0]))
    {
        echo 'UserName cannot begin with a number';
    exit();
    }

else
{

    //hash the password and apply your own mysterious unique salt
    crypt($p);

    include_once("randStrGen.php");
    $p_hash = randStrGen(20)."$p".randStrGen(20);
    //Add use info into the database
    echo"$u $e $p_hash $g $c $ip";
    $sql = "INSERT INTO users(username,email,password,gender,country,ip,signup,lastlogin,notescheck) VALUES('$u','$e','$p_hash','$g','$c','$ip,now(),now(),now())";
    $query = mysqli_query($db_conx,$sql);

    $uid = mysqli_insert_id($db_conx);
    //Establish their row in the useroptions table

    //$sql = "INSERT INTO useroptions(id,username,background)VALUES('$uid','$u','original')";
    //$query = mysqli_query($db_conx,$sql);

    // Creat directory to hold each user's files(pics,mp3s,etc)
    if(!file_exists("user/$u")){
        mkdir("user/$u",0755);
    }
//email the user their activation link
$to = "$e";
$from = "noreply@maxdudes.com";
$subject = 'maxdudes Account Activation';

//$message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.maxdudes.com"></a>maxdudes Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.maxdudes.com/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
$message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.yoursitename.com"><img src="http://www.yoursitename.com/images/logo.png" width="36" height="30" alt="yoursitename" style="border:none; float:left;"></a>yoursitename Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.yoursitename.com/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
    $headers = "From: $from\n";
       $headers .= "MIME-Version: 1.0\n";
      $headers .= "Content-type: text/html; charset=iso-8859-1\n";
//mail($to, $subject, $message, $headers);

echo "signup_success";
exit();
}

exit();
    }

?>

推荐答案

_POST [ u])){
// 连接到数据库
include_once( db_conx.php);
// 将发布的数据收集到本地变体

< span class =code-sdkkeyword>
_POST["u"])){ //CONNECT TO THE DATABASE include_once("db_conx.php"); //GATHER THE POSTED DATA INTO LOCAL VARIALES


u = preg_replace(' #[^ a-z0-9] #i'' '


_POST [' u']);
_POST['u']);


这篇关于无法将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆