[英]PHP undeclared variables error
我的代码和表格:
<?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>
按下“提交”按钮时我想要发生的事情的代码:
<?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);
}
?>
我得到的错误:
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
第 63 行是我提交按钮代码中的以下行:
SET content_title='$content_title', content_text='$content_text' WHERE
这不是宣布他们吗?
看起来您正在寻找表单的POST
值。
它们不包含在变量$content_title
和$content_text
。 事实上,你的错误告诉你你没有为这些变量分配任何东西。
它们就像提交的值一样包含在$_POST
数组中。
IE
<?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);
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.