我遇到一些PHP代码问题

时间:2016-04-21 00:04:58

标签: php

一切正常,但是当我点击提交时,我收到的错误是:

Warning: mysqli_query() [function.mysqli-query]: Empty query in /home/gcapriol/public_html/WBG410/final-project/add_review.php on line 19 There was an error: error_message."

我试过修理但是我没有成功。有人可以帮助我吗?这是我的代码:

<?php
$id = $_GET['product.php'];
if(isset($_POST['Submit_A_Review'])){
    $name = $_POST['name'];
    $product = $_POST['product_id'];
    $comments = $_POST['comments'];
    $sql = "SELECT * FROM users WHERE name = '$name' product = '$product_id' AND comments = '$comments";
    if($name==""){
    $nameMsg = "<br><span style='color:red;'>Your name cannot be left blank.</span>";
    }
    if($product==""){
    $productMsg = "<br><span style='color:red;'>The name of the product cannot be left blank.</span>";
    }
    if($comments==""){
    $commentsMsg = "<br><span style='color:red;'>The comments area cannot be left blank.</span>";
    } // comment: more code will be added here
    else{
    include('includes/dbc_admin.php');
    $success = mysqli_query($con, $query); <---- here is where the warning is pointing to
    if($success){
        $inserted = "Success! A review has been added.";
    }
    else{
        $error_message = mysqli_error($con);
        $inserted = "There was an error: error_message";
        exit($inserted);
    }
    }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>My Gaming Products Site</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javacript">
function validateForm(){
    var name = document.form1.name.value;
    var product = document.form1.product.value;
    var comments = document.form1.comments.value;
    var nameMsg = document.getElementByld('nameMsg');
    var productMsg = document.getElementByld('productMsg');
    var commentsMsg = document.getElementByld('commentsMsg');
    if(name==""){nameMsg.innerHTML = "Your name cannot be left blank.";return false;}
    if(product==""){productMsg.innerHTML = "The name of the product cannot be left blank.";return false;}
    if(comments==""){commentsMsg.innerHTML = "The comments area cannot be left blank.";return false;}
}
</script>
</head>

<body>

    <?php include("includes/header.inc"); ?>

    <?php include("includes/nav.inc"); ?>

<div id="wrapper">



    <?php include("includes/aside.inc"); ?>

    <section>
    <h2>Add A Review</h2><!-- Reference Point - Do Not Retype! -->
        <?php if(isset($inserted)){echo $inserted;}
        else{ ?>
    <form method="post" action="<?php
    echo $_SERVER['PHP_SELF']?>"
    name="form1" onSubmit="return validateForm()">
    <p><label>Name:</label><br><input type="text" id="name" name="name">
    <?php
        if(isset($nameMsg)){
        echo $nameMsg;
        }
    ?> <br><span id="nameMsg" style="color:red"></span>
    </p>
    <p><label>Product:</label><br><input type="text" id="product" name="product">
    <?php
        if(isset($productMsg)){
        echo $productMsg;
        }
    ?> <br><span id="productMsg" style="color:red"></span>
    </p>
    <p><label>Comments:</label><br><textarea id="comments" name="comments"></textarea>
    <?php
        if(isset($commentsMsg)){
        echo $commentsMsg;
        }
    ?> <br><span id="commentsMsg" style="color:red"></span>
    </p>
    <p><input type="submit" name="Submit_A_Review" value="Submit"></p>
    </form><!-- Reference Point - Do Not Retype! -->
        <?php } ?>
    </section>

</div>
    <?php include("includes/footer.inc"); ?>

</body>
</html>

注意:要求任何人为我解决问题,我只是要求指出正确的方向。

1 个答案:

答案 0 :(得分:0)

var $query为空,这就是您收到错误的原因。您的SQL查询位于var $sql

更改自:

$success = mysqli_query($con, $query);

$success = mysqli_query($con, $sql);
相关问题