PHP undeclared variables error -
my code , form:
<?php include("includes/connect.php"); $content = "select * content 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 want happen when 'submit' button pressed:
<?php include("includes/connect.php"); if(isset($_post['submit'])){ $order = "update content set content_title='$content_title', content_text='$content_text' content_page='home'"; mysql_query($order); }
?>
the error 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 following line submit button code:
set content_title='$content_title', content_text='$content_text'
is not declaring them?
it looks looking post
values of form.
they not contained in variables $content_title
, $content_text
. in fact error telling you haven't assigned variables.
they contained in $_post
array value of submit.
i.e
<?php include("includes/connect.php"); if(isset($_post['submit'])){ //sanitize data , assign value 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' content_page='home'"; mysql_query($order); } ?>
Comments
Post a Comment