Jump to content

Undefined Index problem in PHP Code


m@m

Recommended Posts

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

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] ?>" >

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.