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

时间:2017-09-26 05:58:44

标签: php mysql mysqli

嗨,我是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有什么关系吗?提前谢谢你:)

2 个答案:

答案 0 :(得分:3)

放置代码块

$bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AppBundle\AppBundle(),
        new FOS\UserBundle\FOSUserBundle(),
    );

里面的

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

正好在$ sql = [...]

之下

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

答案 1 :(得分:0)

低于$ sql,取一个变量

<class 'novaclient.base.ListWithMeta'>