Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
hello everyone i am getting a problem while updating my record..when i click the edit button it doesnot update the record but give following errors to all post variables.. i would really appreciate any kind of comments or help...
this is courses-edit.php
<?php include("../includes/config.php"); ?> <?php if ($_SESSION["isteacher"]) { $con=mysql_connect($dbserver,$dbusername,$dbpassword); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con); $courseid=$_GET["id"]; $result = mysql_query("SELECT * FROM courses WHERE (id='".$courseid."')"); while($row = mysql_fetch_array($result)) { $id=$row['id']; $title = $row['title']; $des = $row['description']; $subjectid = $row['subjects-id']; } mysql_close($con); ?> <script type="text/javascript"> $(function() { $("form").validity(function() { $("#title") .require("This Field Must Be Filled!!") }); }); </script> <?php include("../includes/header.php"); ?> <?php include("includes/nav.php"); ?> <div id="maincontent"> <div class="span-24 last"> <div id="breadcrumbs"> <a href="index.php">Home</a> > <a href="manage-courses.php">Manage Courses</a> > <a href="courses-list.php">List Courses</a> > Edit Course </div> </div> <?php include("../teacher/includes/manage-courses-aside.php"); ?> <div class="span-18 last"> <h2 class="alt">Edit Course</h2> <form id="form" method="post" action="courses-edit-action.php"> <input type="hidden" value="<?php echo $courseid; ?>" name="id" /> <label>Course Name:</label><input type="text" name="title" id="title" class="text" value="<?php echo $title; ?>" /><br /><br /> <label>Choose Subject:</label> <?php $con=mysql_connect($dbserver,$dbusername,$dbpassword); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con); $result = mysql_query("SELECT * FROM subjects"); echo "<select name='subjects-id'>\n"; while($row = mysql_fetch_array($result)) { echo "<option value='".$row['id'] . "'"; if ($subjectid==$row['id']) echo 'selected="selected"'; echo " >" . $row['subjectname'] . "</option>\n"; } echo "</select>\n"; mysql_close($con); ?> <label>Description:</label><textarea name="description" id="description"><?php echo $des; ?></textarea><br /> <br /> <input type="submit" value="Edit Course" class="button" /> </form> <?php include("../includes/footer.php"); ?> <?php } else { header("Location: ".$fullpath."login/unauthorized.php"); } ?> and this is courses-edit-action.php
<?php include("../includes/config.php");?> <?php $id=$_POST["id"]; $title=$_POST["title"]; $des=$_POST["description"]; $subjectid=$_POST["subjects-id"]; $con=mysql_connect($dbserver,$dbusername,$dbpassword); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ombts", $con); $query=("UPDATE courses SET title='".$title."', description='".$des."', 'subjects- id'='".$subjectid."' WHERE (id='".$id."')"); $query=mysql_query($query); if($result){ echo header("Location:manage-courses.php?status=2"); } mysql_close($con); ?> and the warnings are
Notice: Undefined index: id in C:\xampp\htdocs\project\teacher\courses-edit-action.php on line 4 Notice: Undefined index: title in C:\xampp\htdocs\project\teacher\courses-edit-action.php on line 5 Notice: Undefined index: description in C:\xampp\htdocs\project\teacher\courses-edit-action.php on line 6 Notice: Undefined index: subjects-id in C:\xampp\htdocs\project\teacher\courses-edit-action.php on line 7
print_r($_POST);?<input type="hidden" value="<?php echo $courseid; ?>" name="id" />the quotes are wrongprint_r($_POST);as suggested above. to see what you're getting.