我的代码和表格:
<?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);
}
&GT;
我得到的错误:
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
这不是宣告它们吗?
答案 0 :(得分:0)
看起来您正在寻找表单的POST
值。
它们不包含在变量$content_title
和$content_text
中。实际上,您的错误告诉您,您尚未为这些变量分配任何内容。
它们包含在$_POST
数组中,就像提交的值一样。
即
<?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);
}
?>