Php - 在表行中显示查询信息

时间:2015-10-21 17:12:22

标签: php mysql

继续收到同样的错误消息

警告:mysqli_error()预计在第29行C:\ xampp \ htdocs \ demetriusdesign777.com \ includes \ functions.php中给出1个参数0 查询失败

<?php 

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

        $db['db_host'] = "localhost";
        $db['db_user'] = "root";
        $db['db_pass'] = "";
        $db['db_name'] = "dd777";

        foreach($db as $key => $value) {
        define(strtoupper($key), $value);
        }

        $connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

        $username = $_POST['username'];
        $email = $_POST['e-mail'];
        $phone = $_POST['phone'];
        $info = $_POST['info'];
        $budget = $_POST['budget'];
        $website = $_POST['website'];

        $query = "INSERT INTO userinfo(name, email, phone, website, info, budget) ";
        $query .= "VALUES ('$username', '$email' '$phone', '$info', '$budget', '$website')";

        $result = mysqli_query($connection, $query);

        if(!$result) {
            die('Query FAILED' . mysqli_error());

        } else {

        echo "Record Create"; 

            }
        }

?>

2 个答案:

答案 0 :(得分:2)

mysqli_error()调用需要一个参数。参数应该是连接句柄。

if(!$result) {
   die('Query FAILED' . mysqli_error($connection));

这会告诉您查询中的实际错误,即参数列表部分中'$email' '$phone',之间缺少的逗号。

$query = "INSERT INTO userinfo
            (name, email, phone, website, info, budget) 
          VALUES 
            ('$username', '$email', '$phone', '$info', '$budget', '$website')";

答案 1 :(得分:1)

  1. 数据库连接不对。
  2. 查询不正确。缺少,(逗号)betwwen '$email''$phone'
  3. mysqli_error($connection)。需要参数。
  4. 使用此编辑的代码。

    <?php 
    if(isset($_POST['submit'])) 
    {
        $DB_HOST = "localhost";
        $DB_USER = "root";
        $DB_PASS = "";
        $DB_NAME = "dd777";
    
        $connection = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
    
        $username = $_POST['username'];
        $email = $_POST['e-mail'];
        $phone = $_POST['phone'];
        $info = $_POST['info'];
        $budget = $_POST['budget'];
        $website = $_POST['website'];
    
        $query = "INSERT INTO userinfo(name, email, phone, website, info, budget) ";
        $query .= "VALUES ('$username', '$email','$phone', '$info', '$budget', '$website')";
    
        $result = mysqli_query($connection, $query);
    
        if(!$result) {
            die('Query FAILED' . mysqli_error($connection));
    
        } else {
    
        echo "Record Create"; 
    
            }
        }   
    }