2012-05-04 13 views
0

最初にこのページが読み込まれるときはいつもコメントがないときに1969年12月31日にコメントされています。コメントが投稿されたときは「列の数が値と一致しませんこのPHPブログのコメントが機能しない

ID int型(11)
COMMENT_DATE日時
のfirst_nameのVARCHAR(50)
のlast_nameのはvarchar(50)
コンテンツはvarchar(500)
post_idのように見えるコメントを 行1" で私のテーブルを数えますint(11)

<?php require_once('Connections/Main.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
} 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) { 
    $insertSQL = sprintf("INSERT INTO blog_comments (first_name, last_name, content, post_id) VALUES (%s, now(), %s, %s, %s)", 
         GetSQLValueString($_POST['first_name'], "text"), 
         GetSQLValueString($_POST['last_name'], "text"), 
         GetSQLValueString($_POST['content'], "text"), 
         GetSQLValueString($_POST['post_id'], "int")); 

    mysql_select_db($database_Main, $Main); 
    $Result1 = mysql_query($insertSQL, $Main) or die(mysql_error()); 
} 

$colname_getSinglePost = "-1"; 
if (isset($_GET['post_id'])) { 
    $colname_getSinglePost = $_GET['post_id']; 
} 
mysql_select_db($database_Main, $Main); 
$query_getSinglePost = sprintf("SELECT post_id, post_date, post_img, content, tags, post_title FROM blog_posts WHERE post_id = %s LIMIT 1", GetSQLValueString($colname_getSinglePost, "int")); 
$getSinglePost = mysql_query($query_getSinglePost, $Main) or die(mysql_error()); 
$row_getSinglePost = mysql_fetch_assoc($getSinglePost); 
$totalRows_getSinglePost = mysql_num_rows($getSinglePost); 

$maxRows_getSingleComments = 20; 
$pageNum_getSingleComments = 0; 
if (isset($_GET['pageNum_getSingleComments'])) { 
    $pageNum_getSingleComments = $_GET['pageNum_getSingleComments']; 
} 
$startRow_getSingleComments = $pageNum_getSingleComments * $maxRows_getSingleComments; 

$colname_getSingleComments = "-1"; 
if (isset($_GET['post_id'])) { 
    $colname_getSingleComments = $_GET['post_id']; 
} 
mysql_select_db($database_Main, $Main); 
$query_getSingleComments = sprintf("SELECT id, first_name, comment_date, last_name, content, post_id FROM blog_comments WHERE post_id = %s", GetSQLValueString($colname_getSingleComments, "int")); 
$query_limit_getSingleComments = sprintf("%s LIMIT %d, %d", $query_getSingleComments, $startRow_getSingleComments, $maxRows_getSingleComments); 
$getSingleComments = mysql_query($query_limit_getSingleComments, $Main) or die(mysql_error()); 
$row_getSingleComments = mysql_fetch_assoc($getSingleComments); 

if (isset($_GET['totalRows_getSingleComments'])) { 
    $totalRows_getSingleComments = $_GET['totalRows_getSingleComments']; 
} else { 
    $all_getSingleComments = mysql_query($query_getSingleComments); 
    $totalRows_getSingleComments = mysql_num_rows($all_getSingleComments); 
} 
$totalPages_getSingleComments = ceil($totalRows_getSingleComments/$maxRows_getSingleComments)-1; 
?> 

//郵便番号...

//コメントコード=

<?php do { ?> 
      <div id="comments" style="border-bottom:1px solid #000; margin-bottom:3px;"> 
      <?php $row_getSingleComments = mysql_fetch_assoc($getSingleComments); ?> 
      <div class="single"> 
<span class="author"><?php echo $row_getSingleComments['first_name']; ?> <?php echo $row_getSingleComments['last_name'];?> commented on <?php $phpdate = strtotime($row_getSingleComments['comment_date']); 
$mysqldate = date('F j, Y',$phpdate); echo $mysqldate; ?> at <?php $mysqltime = date('g:i A',$phpdate); echo $mysqltime; ?></span><br /> 
<?php echo $row_getSingleComments['content']; ?> 
</div> 
      <?php } while ($row_getSingleComments = mysql_fetch_assoc($getSingleComments)); ?> 
      <p>Add a Comment</p> 
      <form method="POST" action="<?php echo $editFormAction; ?>" name="form"> 
      <p> First Name 
       <input type="text" name="first_name" /> 
       <br/> 
       Last Name 
       <input type="text" name="last_name" /> 
       <textarea name="content" cols="60" rows="15"></textarea> 
      </p> 
      <input type="hidden" value="<?php echo $colname_getSinglePost ?>" name="post_id" /> 
      <input type="submit" name="submit" id="submit" value="Submit" style="float:right;" /> 
      <input type="hidden" name="MM_insert" value="form" /> 
      </form> 
     </div> 
     </div> 
     </div> 
    </div><!-- end #content --> 
<?php mysql_free_result($getSinglePost); 

mysql_free_result($getSingleComments);?> 

答えて

0

あなたのSQLフィールドは、それらの入力が一致しません。適切なフィールドに日付を入力していない場合は、次のように変更してください。

INSERT INTO blog_comments (first_name, comment_date, last_name, content, post_id) VALUES (%s, now(), %s, %s, %s) 
関連する問題