Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created November 6, 2020 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/60c7bd17d67b9a95feef22b7a2590f26 to your computer and use it in GitHub Desktop.
Save phpfiddle/60c7bd17d67b9a95feef22b7a2590f26 to your computer and use it in GitHub Desktop.
[ Posted by Arizan Misbah ] php learning register
<?php
require_once "dbcon.php";
$json = file_get_contents('php://input');
$obj = json_decode($json, true);
$username = $obj['username'];
$password = $obj['password'];
$email = $obj['email'];
$query = "SELECT *FROM user where email = '($email)'";
$query_output = mysqli_query($conn, $query);
$count = mysqli_num_rows($query_output);
if($count == 1) {
$arr = array("result"=>"email_already_present");
echo json_encode($arr);
}elseif ($count==0) {
$query1 = "INSERT INTO 'user'('email', 'password', 'username') VALUES ('{$email}', '{password}', '{$username}')";
$query_output1 = mysqli_query($conn, $query1);
$arr = array('result'=>'ok');
echo json_encode($arr);
}else {
$arr = array('result'=>'fail');
echo json_encode($arr);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment