警告:mysqli_query()[function.mysqli-query]:第30行的C:\ xampp \ htdocs \ tempahperalatan \ page1.php中的空查询错误:

hi im a beginner in php can anyone tell me what's the problem here? i cant seem to solve it. this is my php coding:

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

does it has anything to do with my xampp? thankyou in advance :)

Put your code block

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

inside the

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

just below the $sql = [...]

otherwise the script will try to execute a non existent query if your form isn't submitted

below $sql ,Take one Variable

$res=mysqli_query($conn,$sql);
$rows=mysqli_affected_rows($conn);
if($rows!=0)
{
  echo "Record inserted";
}