Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Notice: Undefined variable: item_id in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\editmaster.php on line 100
readonly>
Notice: Undefined variable: item_name in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\editmaster.php on line 101
>
Notice: Undefined variable: description in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\editmaster.php on line 102
>
Notice: Undefined variable: item_category in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\editmaster.php on line 103
>
Notice: Undefined variable: pic in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\editmaster.php on line 104
>


this viewitems.php
<?php 
    include "navigation.php";
    include "header.php";
    include "footer.php";
?> 
<?php
	
	include("../dbConfig.php");

	$query = "SELECT item_id,item_name,description,item_category,pic FROM lost_items_table";
	$returnD = mysql_query($query);
	$returnD1 = mysql_query($query);
	$result = mysql_fetch_assoc($returnD);

?>

            <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                    	<h1 class="page-header">View Items</h1>
                    	<div class="row">
		                    <div class="col-lg-12">
		                        <div class="panel panel-default">
		                        	<div class="panel-heading">View Items</div>
									<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
										<tr>
											<th>Item Id</th>
											<th>Item Name</th>
											<th>Description</th>
											<th>Item category</th>
											<th>Picture</th>
											<th>Edit</th>
											<th>Delete</th>
										</tr>
										<?php
											while($result1 = mysql_fetch_assoc($returnD1)){
											?>
											<tr>
												<td>
													<a href="adminPage.php?activity=itemdetails&item_name=<?php echo $result1['item_name']; ?>"> <?php echo $result1['item_id']; ?> </a>
												</td>
												<td><?php echo ucfirst($result1['item_name']); ?></td>
												<td><?php echo ucfirst($result1['description']); ?></td>
												<td><?php echo ucfirst($result1['item_category']); ?></td>
												<td><?php echo ucfirst($result1['pic']); ?></td>
												<td>	
													<a href="editmaster.php?item_id=<?php echo $row["item_id"]; ?>">Edit</a>
												</td>
												<td>
													<a href="adminPage.php?activity=deleteitem&item_name=<?php echo $result1['item_name']; ?>">Delete</a>
												</td>
											</tr>
											<?php
											}
										?>
										
									</table>
	                                <!-- /.table-responsive -->
                                   </div>
								</div>
				                    <!-- /.panel -->
				            </div>
				                <!-- /.col-lg-12 -->
				        </div>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->


What I have tried:

this my editmaster.php
<?php session_start();
    include("../dbConfig.php");
    include "navigation.php";
    include "header.php";
    include "footer.php";

{

}

				    if (isset($_POST['updateitem']))
				{

				    if (is_numeric($_POST['item_id']))
				{

					$item_id = $_POST['item_id'];
					$item_name = mysql_real_escape_string(htmlspecialchars($_POST['item_name']));
					$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
					$item_category = mysql_real_escape_string(htmlspecialchars($_POST['item_category']));
					$pic = mysql_real_escape_string(htmlspecialchars($_POST['pic']));

				if ($item_name == '' || $description == '' || $item_category == '' || $pic == '')
				{

				$error = 'ERROR: Please fill in all required fields!';

				valid($item_id, $item_name, $description, $item_category, $pic, $error);
				}
				else
				{

				mysql_query("UPDATE lost_items_table SET item_name = '$item_name', description = '$description', item_category = '$item_category', pic = '$pic' WHERE item_id = '$item_id'")
				or die(mysql_error());

				header("Location: viewitems.php");
				}
				}
				else
				{

				echo 'Error!';
				}
				}
				else

				{

				if (isset($_GET['item_id']) && is_numeric($_GET['item_id']) && $_GET['item_id'] > 0)
				{

				$item_id = $_GET['item_id'];
				$result = mysql_query("SELECT * FROM lost_items_table WHERE item_id=$item_id")
				or die(mysql_error());
				$row = mysql_fetch_array($result);

				if($row)
				{

				$item_name = $row['item_name'];
				$description = $row['description'];
				$item_category = $row['item_category'];
				$pic = $row['pic'];

				valid($item_id, $item_name, $description, $item_category, $pic,'');
				}
				else
				{
				echo "No results!";
				}
				}
				else

				{
				echo 'Error!';
				}
}

?>


					
	   <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">	            
					            <!-- /.row -->
					            <div class="row">
					                <!--div class="col-md-8 col-md-offset-4"-->
					                <div class="col-lg-6">
					                    <div class="Register-panel panel panel-default">
					                    <!--div class="panel panel-default"-->
					                        <div class="panel-heading">
					                            Edit Item
					                        </div>
					                        <div class="panel-body">
					                            <div class="row">
					                                <div class="col-lg-6">
					                                	<div class="panel-body">
						                            		<form role="form" action="">
						                            					<input type="text" name="item_id" value=<?php echo $item_id; ?> readonly><br>
						                            					<input type="text" name="item_name" required autofocus placeholder="Item-Name" value=<?php echo $item_name; ?>><br>
						                            					<input type="text" name="description" required autofocus placeholder="Description" value=<?php echo $description; ?>><br>
						                            					<input type="text" name="item_category" required autofocus placeholder="Item_category" value=<?php echo $item_category; ?>><br>
						                            					<input type="text" name="pic" required autofocus placeholder="pic" value=<?php echo $pic; ?>><br>

						                            					<input type="submit" name="updateitemBtn" value="Update">
						                            		</form>
						                                </div>
					                                </div>
					                                <!-- /.col-lg-6 (nested) -->
					                            </div>
					                            <!-- /.row (nested) -->
					                        </div>
					                        <!-- /.panel-body -->
					                    </div>
					                    <!-- /.panel -->
					                </div>
					                <!-- /.col-lg-12 -->
					            </div>
					            <!-- /.row -->
			</div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->
Posted
Updated 12-Jul-18 23:00pm
v3

1 solution

Local variables have a scope. That means that they are only accessible within the block where they are defined. See PHP: Variable scope - Manual[^].

The variables from your error messages are defined in a block enclosed by two if conditions. So you can use them only within this block.

A possible solution would be defining them on top of the code with empty content:
PHP
$item_id = '';
$item_name = '';
$description = '';
$item_category = '';
$pic = '';
if (isset($_POST['updateitem']))
{
    // ...
}
// The variables can be used here
However, you would probably have to add an additional check to define what is displayed when the variables has not been set (are still empty).
 
Share this answer
 
Comments
harristars 13-Jul-18 4:46am    
when i select edit nothing is showing in the form
Jochen Arndt 13-Jul-18 5:20am    
Read my last sentence.

You are always displaying the form even if no data are posted or an error occured. In such cases you should show something else when there are no POST data respectively an error message (both as HTML page to be visible in the browser).

But this is not related anymore to the initial question.
harristars 13-Jul-18 5:31am    
yah the previous error now is gone.The problem the big problem is nothing is being displayed on the editmaster.php when i click edit button on viewitems.php.
Jochen Arndt 13-Jul-18 5:40am    
Again: That is a different problem which usually requires a new question.

Otherwise we might get a thread of many comments here between us two because no other would join such comment threads to solve new questions.

However, you are calling editmaster.php from viewitems.php passing the single argument 'item_id'. But in editmaster.php you check for two parameters: 'updateitem' and 'item_id'.

So the complete database related block is never executed. If you would have displayed a corresponding page when no / not all required data has been posted - as suggested by me - you would have noticed that.
harristars 13-Jul-18 5:37am    
this the error i am get
/editmaster.php?item_id=Notice: Undefined variable: row in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\viewitems.php on line 49

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900