将数据插入表(mysqli)

时间:2017-05-16 20:25:52

标签: php android-studio mysqli

我正在尝试从编辑文本中插入有关注册活动的数据。我尝试通过手机上的应用程序将数据插入数据库。我的桌子上有新行,但所有字段都包含“1”。请帮我解决这个问题。

的config.php

<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$query = "SELECT referrer FROM referrals";
$result = $conn->query($query);
$ref=mysqli_fetch_array($result);
$referrer=$ref['referrer'];

//Create referral URL
$refurl="http://example.com/ref/$referrer";

// Now you have to tell PHP to redirect to this other page
header("Location: $refurl");
?>

insert.php

<?php
   define('SERVER', "localhost");
   define('USER', "root");
   define('PASS', "");
   define('DB', "db");
?>

register.java

<?php

$response = array();

$nik = isset($_POST['nik']);
$username = isset($_POST['username']);
$kata_kunci = isset($_POST['kata_kunci']);
$pin = isset($_POST['pin']);
$hak_akses = isset($_POST['hak_akses']);
$nama = isset($_POST['nama']);
$tipe = isset($_POST['tipe']);
$status_akun = isset($_POST['status_akun']);
$status_lapor = isset($_POST['status_lapor']);

require_once 'config.php';
$con = new MySQLi(SERVER, USER, PASS, DB);

$myQuery = "INSERT INTO tbllogin (`nik`, 'username', 'kata_kunci', 'pin', 'hak_akses', 'nama', 'tipe', 'status_akun', 'status_lapor')
            VALUES ('".$nik."', '".$username."', '".$kata_kunci."', '".$pin."', '".$hak_akses."', '".$nama."', '".$tipe."', '".$status_akun."', '".$status_lapor."')";

if(mysqli_query($con,$myQuery)) {
    $response["success"] = 200; 

    echo json_encode($response);
} else {
    $response["success"] = 404;
    $response["message"] = "page not found";

    echo json_encode($response);
}
?>
在我尝试通过手机上的应用程序插入数据后,这是result(索引3)。

0 个答案:

没有答案