PHP Ajax Post Sorunu |
3 Mesajlar | 549 Okunma |
<script>
function kayitOl(){
var frmval = $("#reg_formu").serialize();
var errmsg = document.getElementById("errmsg");
$.ajax({
type: "POST",
url: "register.php",
data: frmval,
success: function(veri){
if($.trim(veri) == "basarisiz"){
errmsg.innerHTML = 'Kayıt esnasında bir sorun oluştu. Lütfen Daha sonra tekrar deneyiniz!...
';
}else if($.trim(veri) == "bos"){
errmsg.innerHTML = 'Boş alan bırakmayınız!...
';
}else if($.trim(veri) == "basarili"){
errmsg.innerHTML = 'Kayıt işlemi başarıyla tamamlandı!...
';
}else if($.trim(veri) == "mevcut"){
errmsg.innerHTML = 'Böyle bir kullanıcı zaten mevcut!...
';
}
}
});
}
</script>
require_once('config.php');
if($_POST){
function getUserIP()
{
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'Unknown IP Address';
return $ipaddress;
}
$user_count = mysql_query("SELECT * FROM tbl_users");
$user_say = mysql_query("SELECT count(*) FROM tbl_users");
$user_id = '1000'.$user_say + 1;
$user_firstname = strip_tags(trim(mysql_real_escape_string($_POST["user_firstname"])));
$user_lastname = strip_tags(trim(mysql_real_escape_string($_POST["user_lastname"])));
$user_avatar = 'uploads/default_avatar.png';
$user_nickname = strip_tags(trim(mysql_real_escape_string($_POST["user_nickname"])));
$user_email = strip_tags(trim(mysql_real_escape_string($_POST["user_email"])));
$user_gender = strip_tags(trim(mysql_real_escape_string($_POST["user_gender"])));
$user_birthday = strip_tags(trim(mysql_real_escape_string($_POST["user_birthday"])));
$user_location = strip_tags(trim(mysql_real_escape_string($_POST["user_location"])));
$user_inlocation = strip_tags(trim(mysql_real_escape_string($_POST["user_inlocation"])));
$user_password = md5(sha1(strip_tags(trim($_POST["user_password"]))));
$user_repassword = sha1(md5(strip_tags(trim(mysql_real_escape_string($_POST["user_repassword"])))));
$user_online = '0';
$user_apikey = bin2hex(openssl_random_pseudo_bytes(96));
$user_regaddr = getUserIP();
$user_regdate = date('d.m.Y');
$user_totposrespect = '0';
$user_totnesrespect = '0';
$user_totquestions = '0';
$user_totcomments = '0';
if(!$user_nickname || !$user_password){
echo 'bos';
}else{
$varmi = mysql_query("SELECT * FROM tbl_users WHERE user_nickname='$user_nickname'");
$say = mysql_num_rows($varmi);
if($say > 0 ){
echo 'mevcut';
}else{
$kayit_ol = mysql_query("INSERT INTO tbl_users VALUES ('$user_id', '$user_firstname', '$user_lastname', '$user_avatar', '$user_nickname', '$user_email', '$user_gender', '$user_birthday', '$user_location', '$user_inlocation', '$user_password', '$user_repassword', '$user_online', '$user_apikey', '$user_regaddr', '$user_regdate', '$user_totposrespect', '$user_totnesrespect', '$user_totquestions', '$user_totcomments'");
if($kayit_ol){
echo 'basarili';
}else{
echo 'basarisiz';
}
}
}
}
?>