gpt4 book ai didi

php连接数据库mysql的简单代码

转载 作者:行者123 更新时间:2023-11-29 05:18:12 25 4
gpt4 key购买 nike

<分区>

我是 PHP 编程的新手。我确实创建了用于保存数据的简单代码,其中我使用 JSON 从 android 应用程序获取数据,但是当我测试我的 php 代码时,出现了这样的错误

解析错误:语法错误,意外的T_ISSET in E:\Ampps\www\koneksi\insert_data.php on line 12

我的代码

<?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);
}
?>

这是第 12 行的代码

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'])) 

需要你们的帮助很抱歉英语不好

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com