Skip to content
Snippets Groups Projects
Commit 1ce3f7f2 authored by Akmal Fadlurohman's avatar Akmal Fadlurohman
Browse files

Menambahkan ajax pada halaman sign up

parent 7b57a4d6
1 merge request!45OneHundred - 13515005 - Husnulzaki Wibisono Haryadi
......@@ -15,15 +15,10 @@ body {
}
input{
width: 100%;
width: 90%;
margin: 1px auto 15px;
}
input[type="checkbox"]{
width: 0;
margin-right: 10px;
}
a:link, a:visited {
color: rgb(250,250,250);
text-decoration: none;
......
......@@ -3,7 +3,7 @@
<head>
<title>Login to OneHundred</title>
<link rel="stylesheet" type="text/css" href="../css/default_style.css">
<link rel="stylesheet" type="text/css" href="../css/login.css">
<link rel="stylesheet" type="text/css" href="../css/login.css">
</head>
<body>
<div id="login_frame" class="frame">
......
......@@ -26,7 +26,7 @@
</script>";
header("Location: login.html");
}
mysql_close($conn);
mysql_close();
}
}
?>
......@@ -2,7 +2,8 @@
<html>
<head>
<title>Sign Up</title>
<link rel="stylesheet" type="text/css" href="../css/main.css">
<link rel="stylesheet" type="text/css" href="../css/default_style.css">
<link rel="stylesheet" type="text/css" href="../css/login.css">
</head>
<body>
<div id="sign_up_frame" class="frame">
......@@ -12,11 +13,11 @@
<p id="error_signup" style="text-align: center;"></p>
<form name="sign_up" method="post" action="sign_up.php" onsubmit="return validate_password();">
Your name*
<input type="text" name="full_name"><br/>
<input type="text" name="full_name">
Username*
<input type="text" name="user_name"><br/>
<input type="text" name="username" onkeyup="checkAvailability(this.name,this.value)"><label id="username_verification"></label></br>
Email*
<input type="Email" name="user_email"><br/>
<input type="Email" name="user_email"onkeyup="checkAvailability(this.name,this.value)"><label id="email_verification"></label></br>
Password*
<input type="Password" name="user_password"><br/>
Confirm password*
......@@ -25,7 +26,7 @@
<input type="text" name="user_phone"><br/>
<input type="button" value="Sign me up as driver" id="signAs_driver" style="width : 40%" onclick= "driver_signup();"><label id="driversign_status"><br></label>
<input type="text" name="is_driver" style="display:none">
<input type="text" name="is_driver" value="No" style="display:none">
<input type="submit" value="REGISTER">
</form>
<p><br>* Required field</p>
......@@ -48,6 +49,27 @@
document.getElementById("signAs_driver").style.display = "none";
document.sign_up.is_driver.value = "Yes";
}
function checkAvailability(name,value)
{
xhttp = new XMLHttpRequest();
if (value.length == 0) {
document.getElementById("username_verification").innerHTML = "";
document.getElementById("email_verification").innerHTML = "";
return;
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (name === "username") {
document.getElementById("username_verification").innerHTML = this.responseText;
} else if (name === "user_email") {
document.getElementById("email_verification").innerHTML = this.responseText;
}
}
};
var str = name+"="+value;
xhttp.open("GET", "sign_up.php?key="+str, true);
xhttp.send();
}
</script>
</body>
......
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST['full_name']) &&
!empty($_POST['user_name']) &&
!empty($_POST['username']) &&
!empty($_POST['user_email']) &&
!empty($_POST['user_password']) &&
!empty($_POST['confirm_password']) &&
......@@ -14,7 +14,7 @@
$password = $_POST['user_password'];
$phone = $_POST['user_phone'];
if(isset($_POST['is_driver']))
if($_POST['is_driver'] == "Yes")
{
$status = 'driver';
}
......@@ -26,9 +26,13 @@
$query = mysql_query("INSERT INTO user (name,email,phone,username,password,status,pict) VALUES ('$fullname', '$email', '$phone', '$username', '$password', '$status',DEFAULT)") or die(mysql_error());
if($query)
{
header("Location: ../order/order.html");
if ($status == "customer") {
header("Location: ../order/order.html");
} else {
header("Location: ../profile_page/profile.html");
}
}
mysql_close($conn);
mysql_close();
}
else {
include("sign_up.html");
......@@ -37,5 +41,26 @@
</script>";
header("Location: sign_up.html");
}
} else if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (!empty($_GET['key'])) {
$key = stristr($_GET['key'],'=',true);
$value = substr(strstr($_GET['key'],'='),1);
include '../database/dbconnect.php';
if ($key == "username") {
$query = mysql_query("SELECT * FROM user WHERE username='".$value."'") or die(mysql_error());
$numrows=mysql_num_rows($query);
} else if ($key == "user_email") {
$query = mysql_query("SELECT * FROM user WHERE email='".$value."'") or die(mysql_error());
$numrows=mysql_num_rows($query);
}
if ($numrows != 0) {
echo " X";
} else {
echo " Ok";
}
mysql_close();
}
}
?>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment