SyntaxError: Unexpected token ( in JSON at position 0

mau nanya mas ini ane ada form login pas masukin username:password dengan benar trus klik login muncul json error kek gni: SyntaxError: Unexpected token ( in JSON at position 0 muncul pesan itu bukan berarti gagal si form login nya harus di refresh lagi baru masuk ke Dashboard, kodenya mas :
<?php
set_time_limit(0);
error_reporting(0);
session_start();
require_once('mainconfig.php');
if($_SESSION['account'])
	die('Failed!');
if(!$_POST['username']||!$_POST['password']){
}else{
	header('Content-Type: application/json');
	$username = trim($_POST['username']);
	$cekuser = mysql_query("select * from members where username = '$username'");
	if(mysql_num_rows($cekuser)<1)
		die(json_encode(array('result' => 0, 'content' => 'Username/Password salah!')));
	$hasil=mysql_fetch_assoc($cekuser);
	if(trim($_POST['password'])<>$hasil['password'])
		die(json_encode(array('result' => 0, 'content' => 'Username/Password salah!')));
	$_SESSION['account'] = $hasil;
	print json_encode(array('result' => 1, 'content' => 'Login Berhasil!,anda akan dialihkan..', 'redirect' => '?'));
}
apa ada yang salah ? biar waktu submit langsung ngejalanin perintah ini
json_encode(array('result' => 1, 'content' => 'Login Berhasil!,anda akan dialihkan..', 'redirect' => '?'));
avatar simuf

@simuf

42 Kontribusi 4 Poin


Jawaban

Kalau begini mas? gimana hasilnya? nyoba doang si saya
<?php
set_time_limit(0);
error_reporting(0);
session_start();
require_once('mainconfig.php');
if($_SESSION['account'])
	die('Failed!');
if(!$_POST['username']||!$_POST['password']){
}else{
	$username = trim($_POST['username']);
	$cekuser = mysql_query("select * from members where username = '$username'");
	if(mysql_num_rows($cekuser)<1)
		die(json_encode(array('result' => 0, 'content' => 'Username/Password salah!')));
	$hasil=mysql_fetch_assoc($cekuser);
	if(trim($_POST['password'])<>$hasil['password'])
		die(json_encode(array('result' => 0, 'content' => 'Username/Password salah!')));
	$_SESSION['account'] = $hasil;

	header('Content-Type: application/json');
	print json_encode(array('result' => 1, 'content' => 'Login Berhasil!,anda akan dialihkan..', 'redirect' => '?'));
}
avatar CodenameJR

@CodenameJR

278 Kontribusi 107 Poin


hasil nya SyntaxError: Unexpected token F in JSON at position 0 mas makasih udah mampir :D /
avatar simuf

@simuf

42 Kontribusi 4 Poin


$_SESSION['account'] tambahkan @
menjadiย  => @$_SESSION['account']ย 
avatar Edopra

@Edopra

1 Kontribusi 0 Poin


Login untuk gabung berdiskusi