m@m Posted February 1, 2014 Share Posted February 1, 2014 I'm using this code to Edit fom. Error : Notice: Undefined index: Title in C:\wamp\www\MyProject\admin\edit.php on line 96 Here i have paste the coding(I've removed some coding part..issue arise on Line 68 in this pasted code ) <?php $id = isset($_REQUEST['Id']) ? $id = $_REQUEST['Id'] : ''; if ($id != 0) { mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("halftimedb") or die(mysql_error()); $sql = "SELECT Id,Title,description,Image,Category from News WHERE Id='" . $id . "'"; $query = mysql_query($sql); $row = mysql_fetch_array($query); ?> <form action="edit.php" method="POST" enctype="multipart/form-data"> <div class="OuterWrapper" background-color:white; > <div class="row" id="wrapper" > <div class="col-xs-3" style="margin-top:5%"> Title </div> <div class="col-xs-3" style="margin-top:5%"> <input type="hidden" name="Title" class="form-control" value="<?php echo $row[0] ?>" > <input type="text" name="Title" class="form-control" value="<?php echo $row[1] ?>" > </div> </div> <div class="row"> <div class="col-xs-3"> Description </div> <div class="col-xs-3"> <input type="text" name="description" class="form-control" value="<?php echo $row[2]; ?>"> </div> </div> <div class="row"> <div class="col-xs-3"> Image </div> <div class="col-xs-3"> <div> <img src='data:image/jpeg;base64,<?php echo base64_encode($row[3]) ?>' /> </div> <input type="file" name="image"> </div> </div> <div class="row"> <div class="col-xs-3"> Category </div> <div class="col-xs-3"> <select name="select_category" class="form-control"> <option value="0" <?php if ($row[4] == '0') echo 'selected'; ?> >-- Select Category --</option> <option value="1" <?php if ($row[4] == '1') echo 'selected'; ?>>What's New</option> <option value="2" <?php if ($row[4] == '2') echo 'selected'; ?>>The Time For a Program</option> <option value="3" <?php if ($row[4] == '3') echo 'selected'; ?>>Event Information</option> </select> </div> </div> <div class="row"> <div class="col-xs-3" style="margin-left:28%"> <input type="submit" name="submit" value="Submit" class="btn btn-default"> </div> <div> </form> <?php $Title = mysql_real_escape_string($_POST["Title"]); // <-- Undefined Index Title Line 96 //$description_save = $_POST['description']; //$Category = $_POST["select_category"]; mysql_query("UPDATE News SET Title ='$Title', Description ='$description_save' WHERE Id = '$id'") or die(mysql_error()); echo "Succesfully Updated!"; //header("Location: list.php"); } ?> Can anyone please help me to solve this issue............ Link to comment https://forums.phpfreaks.com/topic/285864-undefined-index-problem-in-php-code/ Share on other sites More sharing options...
ginerjm Posted February 1, 2014 Share Posted February 1, 2014 If you wrapped your code in the proper tags it would be easier to work with. Also - if THIS code is not actually what produced that message, please give us the right code. Link to comment https://forums.phpfreaks.com/topic/285864-undefined-index-problem-in-php-code/#findComment-1467358 Share on other sites More sharing options...
cyberRobot Posted February 1, 2014 Share Posted February 1, 2014 This probably isn't the issue, but you have two fields which have both been named "Title": <input type="hidden" name="Title" class="form-control" value="<?php echo $row[0] ?>" > <input type="text" name="Title" class="form-control" value="<?php echo $row[1] ?>" > Link to comment https://forums.phpfreaks.com/topic/285864-undefined-index-problem-in-php-code/#findComment-1467372 Share on other sites More sharing options...
Barand Posted February 1, 2014 Share Posted February 1, 2014 Until the form is submitted, $_POST['Title'] does not exist so when the page first loads you get the error. Check it is set before trying to use it and update the db Link to comment https://forums.phpfreaks.com/topic/285864-undefined-index-problem-in-php-code/#findComment-1467380 Share on other sites More sharing options...
jcbones Posted February 2, 2014 Share Posted February 2, 2014 Pointing you even further in the right direction, use isset(), or empty(). Link to comment https://forums.phpfreaks.com/topic/285864-undefined-index-problem-in-php-code/#findComment-1467402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.