dpz7935 2017-09-26 05:58
浏览 9
已采纳

警告: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 :)

  • 写回答

2条回答 默认 最新

  • douyigua5381 2017-09-26 06:02
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable