基于id向数据库添加注释

时间:2014-01-12 18:19:12

标签: php html database forms comments

我正在制作一个食谱网站,我正在努力让我的评论功能起作用,我之前已经工作到现在我一直收到一个错误,告诉我当我尝试提交时我无法访问数据库评论

我知道这可能看起来很简单,但我完全陷入困境,我一直在试图找到一个可以解决这个问题的方法,但实际上并没有取得任何进展......

这是PHP过程:

    if (!$db_server){
        die("unable to Connect to MYSQL: " . mysqli_connect_error($db_server));
        $db_status = "not connected"; 
    }else{
        if(trim($_POST['submit']) =="submit"){
        }else{              
            if (isset($_POST['dropoption']) && ($_POST['dropoption'] != '')){
                if (isset($_POST['meal']) && ($_POST['meal'] != '')) {

                $dropoption = clean_string($db_server, $_POST['dropoption']);
                $meal = clean_string($db_server, $_POST['meal']);
                $quer = "SELECT * FROM `recipename` WHERE `cuisine_type` ='$dropoption' AND `b_l_d` ='$meal'LIMIT 0,1";
                mysqli_select_db($db_server, $db_database);
                $querya= mysqli_query($db_server, $quer); 
                if (!$querya) die("database access failed: " . mysqli_error($db_server));
                        while($row = mysqli_fetch_array($querya)){
$recipeid .= $row['recipeid'];                          
$recipename .="<h1>". "Why dont you have ".$row['mealname']."</h1>";
                            $ingredients .="<p>".$row['ingredients']."</p>";
                            $recipe .="<p>" .$row['recipe']."</p>";
                            $cookingtime .="<h4>" .$row['hours']." Hours".$row['minutes']." Minutes </h4>";
                            $mealpic .="<img src='http://ml11maj.icsnewmedia.net/Workshops/Week%207/".$row['imagepath']."'/>"; 
                        }
                        if ($comment != ''){
                            $userid = trim($_SESSION['userid']);
                            $comment = trim($_POST['comment']);
                            $userid = clean_string($db_server, $_SESSION['userid']);
                            $comment = clean_string($db_server, $_POST['comment']);
                            $query = "INSERT INTO Comments (comment,userid,recipeid) VALUES ('$comment','$userid','$receipeid')";
                            mysqli_select_db($db_server, $db_database);
                            mysqli_query($db_server, $query) or
                            die("Insert failed: " . mysqli_error($db_server));
                            }                   
                }//if(meal)//
            }//if(cuisine)//    
        } //if(trim)//  
    }
    $query = "SELECT * FROM Comments";
                    $result = mysqli_query($db_server, $query);
                    if (!$result) die ("Database access failed: " . mysqli_error($db_server));
                    while($row = mysqli_fetch_array($result)) {
                        $str_comments .= "<p>" . $row['comment'] . "</p>";
                    }       

这是html表单:

        <?php echo $recipename;
        echo $mealpic;
        ?>

                <h2>Ingredients</h2>
         <?php      
                $ingredientchunks = (explode(",",$ingredients));
                for($i = 1; $i < count($ingredientchunks); $i++){
                    echo "$i.$ingredientchunks[$i] <br/>";}
                echo $cookingtime;
                ?>
                <h2>Recipe</h2>
         <?php
                $recipechunks = (explode(",",$recipe));
                for($i = 1; $i < count($recipechunks); $i++){
                    echo "$i.$recipechunks[$i] </br>";} 
         ?>            
  <form id="results" form method="post" action="results.php">              
            <input type="submit" id="Like" name="Like" value="Like" /> 
            <input type="submit" id="Next" name="Next" value="Next" />     
        </form> 
 <div id=Comments>
  <form id="comments" form method="post" action='results.php?cuisine_type=" . $dropoption ."b_l_d=" . $meal . "'> 
         Comment: <textarea rows="2" cols="30" name="comment" id="comment" placeholder="Anything to say??"></textarea>
            <input type="submit" id="comments" name="comments" value="comments" /> 
            </form>    
                    <?php   
                echo $str_comments;
                require_once "db_close.php";
        ?> 
 </div>

 </p>
<? require_once ('home_stop.php')?>

0 个答案:

没有答案