Search code examples
phpmysqlphpmyadminampps

php simple code to connect database mysql


im new in php programming. i do create simple code for saving data where i get the data from android app using JSON, but when im testing my php code theres an error like this

Parse error: syntax error, unexpected T_ISSET in E:\Ampps\www\koneksi\insert_data.php on line 12

my code

<?php

/*
 * Following code will create a new product row
 * All product details are read from HTTP Post Request
 */

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['jenis_kendaraan']) && isset($_POST['jenis_pelanggaran']) && isset($_POST['wilayah_hukum'])    isset($_POST['barang_sitaan']) && isset($_POST['email']) && isset($_POST['hp']) && isset($_POST['lokasi_sidang'])   && isset($_POST['barang_sitaan_lain'])) {

    $jenis_kendaraan = $_POST['jenis_kendaraan'];
    $jenisPelanggaran = $_POST['jenis_pelanggaran'];
    $barang_sitaan = $_POST['barang_sitaan'];
    $email = $_POST['email'];
    $hp = $_POST['hp'];
    $lokasi_sidang = $_POST['lokasi_sidang'];
    $barang_sitaan_lain = $_POST['barang_sitaan_lain'];


    // include db connect class
    require_once __DIR__ . '/db_connect.php';

    // connecting to db
    $db = new DB_CONNECT();

    // mysql inserting a new row
    $result = mysql_query("INSERT INTO products(jenisKendaraan, jenisPelanggaran, wilayahHukum, barangSitaan,   email, hp, lokasiSidang, barangSitaanLain) VALUES('$jenis_kendaraan', '$jenis_pelanggaran',     '$wilayah_hukum','$barang_sitaan', '$email', '$hp', '$lokasi_sidang', '$barang_sitaan_lain')");

    // check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "Product successfully created.";

        // echoing JSON response
        echo json_encode($response);
    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";

        // echoing JSON response
        echo json_encode($response);
   }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

 // echoing JSON response
    echo json_encode($response);
}
?>

and this is line 12 cointains like

if (isset($_POST['jenis_kendaraan']) && isset($_POST['jenis_pelanggaran']) && isset($_POST['wilayah_hukum']) isset($_POST['barang_sitaan']) && isset($_POST['email']) && isset($_POST['hp']) && isset($_POST['lokasi_sidang']) && isset($_POST['barang_sitaan_lain'])) 

need some help from u guys so sorry for bad english


Solution

  • missing && operator try this

    if (isset($_POST['jenis_kendaraan']) && isset($_POST['jenis_pelanggaran']) && isset($_POST['wilayah_hukum'])  &&  isset($_POST['barang_sitaan']) && isset($_POST['email']) && isset($_POST['hp']) && isset($_POST['lokasi_sidang'])   && isset($_POST['barang_sitaan_lain'])) {