I want to create a registration and login with rest api using PHP mysql in my Application.
This is my code
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credential: true');
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization, Accept, X-Requested-With, x-xsrf-token');
header('Content-Type: application/json; charset=utf-8');
include'config.php';
$postjson = json_decode(file_get_contents('php://input'), true);
$today = date('Y-m-d H:i:s');
if($postjson['aksi'] == 'registration_progress'){
$emailcheck = mysqli_fetch_array(mysqli_query($mysqli, "SELECT email FROM users WHERE email = '$postjson[email]'"));
if($emailcheck['email'] == $postjson['email']){
$result = json_decode(array('success' => false, 'msg' => 'Email Sudah Terdaftar'));
}else{
$password= md5($postjson['password']);
$query = mysqli_query($mysqli, "INSERT INTO users SET
nama_user = '$postjson[nama_user],
email = '$postjson[email],
password = '$password,
createat = '$today',
");
if($query) $result = json_encode(array('success' => true, 'msg' => 'Registrasi Berhasil !!'));
else $result = json_encode(array('success' => false, 'msg' => 'Registrasi Gagal !!'));
echo $result;
}
}elseif($postjson['aksi'] == 'login_progress'){
$password = md5($postjson['password']);
$logindata = mysqli_fetch_array(mysqli_query($mysqli, "SELECT * FROM users WHERE email = '$postjson[email]' AND password = '$password'"));
$data = array(
'id_user' => $logindata['id_user'],
'nama_user' => $logindata['nama_user'],
'email' => $logindata['email']
);
if($logindata){
$result =json_encode(array('success' => true, 'result' => $data));
}else{
$result =json_encode(array('success' => false));
}
echo $result;
}
I don't know my error
Notice Trying to access array offset on value of type null in C:\xampp\htdocs\api-ionic\api.php on line 13
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\api-ionic\api.php on line 31