更新不更新数据库

时间:2014-08-04 05:48:59

标签: php sql

我正在尝试更新数据库信息,但是它没有更新,它确实在提交后显示成功的消息,但是它不想更新。

PHP:

<?php
require_once('../_lib/inc/config.php');
session_start();

    if ($_SESSION['username']) {

    }else {

    }
        $grab = mysql_query("SELECT * FROM reviews WHERE id='" . mysql_real_escape_string($_GET['id']) . "'");
        $row = mysql_fetch_assoc($grab);

        $author = $row['author'];
        $comment = $row['comment'];
        $company = $row['company'];
        $id = $row['id'];
?>

<?php 

    if ($_POST) { 
        $comment = mysql_real_escape_string($_POST['comment']);
        $author = mysql_real_escape_string($_POST['author']);
        $company = mysql_real_escape_string($_POST['company']);   
        $id = mysql_real_escape_string($_POST['id']);     

        if ($author == "") {    
                echo ('<div class="alert alert-error" style="margin: 8px; text-align: center;"><strong>Error:</strong> Please enter something into the author field!</div>');
        }   
        elseif ($company == "") {   
            echo ('<div class="alert alert-error" style="margin: 8px; text-align: center;"><strong>Error:</strong> Please enter something into the company field!</div>');
        }
        elseif($comment == "") {
            echo ('<div class="alert alert-error" style="margin: 8px; text-align: center;"><strong>Error:</strong> Please enter something into the comment field!</div>');  
        } else {

            // Insert the review
            $insertReviews = "UPDATE reviews SET author='$author', company='$company', comment='$comment' WHERE id='" . mysql_real_escape_string($_GET['id']) . "'";
            mysql_query($insertReviews) or die("MySQL Error - Could not insert reviews");

            echo ('<div class="alert alert-success" style="margin: 8px; text-align: center;"><strong>Success:</strong> Your review has been successfully submitted!</div>');        
        } 
    }
        else {  
    }   
?> 

形式:

<form action="reviews/viewReview.php" method="POST" name="#load">

    Review Author:
    <br />
    <input name="author" size="8" type="text" class="userpass" value="<?php echo $author ?>"/>
    <br /><br />

        <input name="id" type="hidden" value="<?php echo $id ?>"/>

    Company Name:
    <br />
    <input name="company" size="8" type="text" class="userpass" value="<?php echo $company ?>"/>
    <br /><br />

    Review Comment:
    <br />
    <textarea id="comment" name="comment" rows="6" cols="35"><?php echo $comment ?></textarea>
    <br /><br />

    <input name="submit" type="submit" class="button" value="Update Article" />

</form>

为什么它没有更新数据库中的信息集?

1 个答案:

答案 0 :(得分:-1)

而不是
        &#34; mysql_real_escape_string($ _ GET [&#39; ID&#39;])&#34;
只需使用
         &#34; mysql_real_escape_string($ _ POST [&#39; ID&#39;])&#34;