-6ren">
gpt4 book ai didi

php - 警告 : mysqli_query() [function. mysqli-query] : Empty query in C:\xampp\htdocs\tempahperalatan\page1. php on line 30 Error:

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:27 25 4
gpt4 key购买 nike

嗨,我是 PHP 的初学者,谁能告诉我这里有什么问题?我似乎无法解决它。这是我的 PHP 编码:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tempahperalatan";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

if(isset($_POST['submit']))
{

$pemohon = $_POST['namaPemohon'];
$trkhMula = $_POST['tmula'];
$trkhAkhir = $_POST['takhir'];
$n_program = $_POST['namaProgram'];
$lokasi = $_POST['lokasi'];
$n_anjuran = $_POST['namaAnjuran'];
$catatan = $_POST['catatan'];

$sql = "INSERT INTO daftartempah (pemohon, trkhMula, trkhAkhir, n_program, lokasi, n_anjuran, catatan) VALUES ('$namaPemohon', '$tmula', '$takhir', '$namaprogram', '$lokasi', '$namaAnjuran', '$catatan')";

}

if (mysqli_query($conn, $sql)) { //this is line 30
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

和我的xampp有关系吗?提前谢谢你:)

最佳答案

把你的代码块

if (mysqli_query($conn, $sql)) { //this is line 30
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

里面

if(isset($_POST['submit']))
{

就在 $sql = [...] 的下方

否则,如果您的表单未提交,脚本将尝试执行不存在的查询

关于php - 警告 : mysqli_query() [function. mysqli-query] : Empty query in C:\xampp\htdocs\tempahperalatan\page1. php on line 30 Error:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46418829/

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