doulan8330 2014-04-08 23:37
浏览 61

PHP未声明的变量错误

My code and form:

<?php
include("includes/connect.php");
$content = "SELECT * FROM content where content_page='home'";
$result = mysql_query($content);
$row = mysql_fetch_array($result);
?>
<form method="post" action="admin_home.php">
Headline:</br>
<input type="text" name="content_title" value="<?php echo "$row[content_title]" ?>"></br>   </br>
Main content:</br>
<textarea type="text" class="txtinput" cols="55" rows="20" name="content_text"><?php echo   "$row[content_text]" ?></textarea></br></br>
<input type="submit" name="submit" value="Save changes">
</form>

Code for what I want to happen when the 'submit' button is pressed:

<?php 

include("includes/connect.php");
if(isset($_POST['submit'])){ 

$order = "UPDATE content 
          SET content_title='$content_title', content_text='$content_text' WHERE content_page='home'";
mysql_query($order);

}

?>

The error I get:

Notice: Undefined variable: content_title in /Applications/XAMPP/xamppfiles/htdocs/templacreations/admin/admin_home.php on line 63

Notice: Undefined variable: content_text in /Applications/XAMPP/xamppfiles/htdocs/templacreations/admin/admin_home.php on line 63

Line 63 is the following line from my submit button code:

SET content_title='$content_title', content_text='$content_text' WHERE 

is this not declaring them?

  • 写回答

1条回答 默认 最新

  • dqtiober37522 2014-04-08 23:41
    关注

    It looks like you are looking for the POST values of your form.

    They are not contained in the variables $content_title and $content_text. In fact your error is telling you that you haven't assigned anything to those variables.

    They are contained in the $_POST array just like the value of the submit.

    I.e

    <?php 
    
    include("includes/connect.php");
    if(isset($_POST['submit'])){ 
      //Sanitize data and assign value to variable 
      $content_title = mysql_real_escape_string($_POST['content_title']); 
      $content_text = mysql_real_escape_string($_POST['content_text']);
    
      $order = "UPDATE content 
                SET content_title='$content_title', content_text='$content_text' 
                WHERE content_page='home'";
      mysql_query($order);
    
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入