更新列id =?

时间:2013-02-11 03:52:10

标签: php mysql

我试图在我的表('ptb_messages')中更新一个列('content'),其中消息的'id'与我提交的表单中回显的那个相同,所以WHERE id ='“。 $ MESSAGE_ID“。这是我设定的全球功能。消息的id正在回复,问题出在函数或mysql脚本中。

是的,有人可能会告诉我这出错的地方。感谢

html表格:

   <form id="reply" action="message_reply.php?to=<?php echo "".$message_id.""; ?>" method="post">
    <textarea name="textarea" id="textarea"><?php echo  "{$message['content']}"; ?></textarea>
    <?php
    }
    ?>
    <input type="image" src="assets/img/icons/email_send.png"
         width="50" height="34" name="send_button" id="send_button">
    </form>



mysql function:



 <?php
    require_once("includes/session.php"); 
    require_once("includes/functions.php");
    require('includes/_config/connection.php');
    ?>
    <?php 

    session_start();

    include 'includes/_config/connection.php'; 

    $textarea = $_POST['textarea'];

    $result = mysql_query("SELECT content FROM ptb_messages WHERE id='".$message_id."'");





    if(!$result) 
    { 
    echo "The username you entered does not exist"; 
    } 
    else 
    if($textarea!= mysql_result($result, 0)) 
    { 
    echo ""; 


        $sql=mysql_query("UPDATE ptb_messages SET content ='".addslashes($textarea)."' WHERE id='".$message_id."'"); 
    }
        if($sql) 
        { 


    }
    header("Location: {$_SERVER['HTTP_REFERER']}");
    ?>

我收到这些错误:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 9 in /Applications/XAMPP/xamppfiles/htdocs/ptb1/message_reply.php on line 25

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/ptb1/message_reply.php:25) in /Applications/XAMPP/xamppfiles/htdocs/ptb1/message_reply.php on line 37

3 个答案:

答案 0 :(得分:0)

更改此

<form id="reply" action="message_reply.php?to=<?php echo "".$message_id.""; ?>

<form id="reply" action="message_reply.php?to=<?php echo $message_id; ?>

并使用此

访问message_id
$result = mysql_query("SELECT content FROM ptb_messages WHERE id='".$GET['to']."'");

答案 1 :(得分:0)

在这种情况下,我无法看到带有message_id的行是否真的存在。如果没有,可能会有问题。如果查询有效但没有返回结果,则Select不返回false。你应该使用:

if (!$result || !mysql_num_rows($result)) {
    echo 'not exists';
}

也许这会解决您的问题。

还有一点需要注意:我看到你在标题之前使用了一些回声。这不应该是因为标题函数会导致错误。在这种情况下使用输出缓冲或在使用标题函数后移动回声。

答案 2 :(得分:0)

您是否尝试过声明$ message_id?

    <?php 

    session_start();

    include 'includes/_config/connection.php'; 

    $message_id=$_GET['to'];

    $textarea = $_POST['textarea'];

    $query = mysql_query("SELECT content FROM ptb_messages WHERE id='".$message_id."'");

 $results=mysql_fetch_array($query);

 $result=$results['0'];

    if($result && $textarea) {

        $sql = mysql_query("UPDATE ptb_messages SET content ='".addslashes($textarea)."' WHERE id='".$message_id."'"); 
  echo 'done';
  }

  else

    { 
    echo "The username you entered does not exist"; 
    }         

    ?>