donglian4770
donglian4770
2015-10-21 17:12

Php - 在表格行中显示查询信息[关闭]

Keep getting this same error message

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\demetriusdesign777.com\includes\functions.php on line 29 Query FAILED

<?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条回答

  • dongwei7245 dongwei7245 6年前
    1. Database connection not right.
    2. Query Not correct. Missing , (comma) betwwen '$email' and '$phone'
    3. put mysqli_error($connection). Require parameter.

    Use This edited code.

    <?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"; 
    
            }
        }   
    }
    
    点赞 评论 复制链接分享
  • duanditang2916 duanditang2916 6年前

    The mysqli_error() call requires a parameter. The parameter should be the connection handle.

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

    This would have told you about the actual error in your query which is the missing comma between '$email' '$phone', in your parameter list section.

    $query = "INSERT INTO userinfo
                (name, email, phone, website, info, budget) 
              VALUES 
                ('$username', '$email', '$phone', '$info', '$budget', '$website')";
    
    点赞 评论 复制链接分享