UPDATE process Error!

I have problem with udating my data via php! I’ve got two files, one is the edit.php for updating & deleting & the other is the messagedata.php for processing.

I’ve got actually two errors.
1st error is whenever I open edit.php a error comes up indicating line 76 bt shows the form & when I select a year for updating the error simply disappears & shows me the data to edit!
Notice: Undefined index: formid in C:\wamp\www\exam1\edit.php on line 76

The second error occurs indicating messagedata.php after I change the data & click UPDATE!

[B]I Notice: Undefined index: result in C:\wamp\www\exam1\messagedata.php on line 74

( ! ) Notice: Undefined index: update in C:\wamp\www\exam1\messagedata.php on line 77

( ! ) Notice: Undefined index: delete in C:\wamp\www\exam1\messagedata.php on line 100[/I][/B]

All line numbers are mentioned in the code! Please HELP!!

the php code for Edit.php is as follows:


<?php $kalam=$_POST['formid'];  //option select name code.  <----Line 76
	   
	   ?>

          <form class="contact_form" name="contact_form" method="post" action="edit.php" name="contact_form">
                    <ul>
					<li>
					<label for="email">Select Year:</label>
					<select name="formid" id="select">
                    <option selected="selected">Year</option>
					</li>
					</ul>		
					
	
	
	<?php
         $sql="SELECT * FROM `data`";
		 $result=mysql_query($sql);
		 while ($rows=mysql_fetch_array($result))
		 {
			 print "<option value=".$rows['year'].">".$rows['year']."</option>";
		 }
	?>
                    </select>
                    
        	<button class="submit" type="submit">Search Now!</button>
       
   </form>

   
   
   
   
    </td>
    
  </tr>
  <?php
  
  $sql=" SELECT * FROM `data` WHERE year='$kalam'";
  $result=mysql_query($sql);
  $rows=mysql_fetch_array($result)
  
  ?>
  
  
  
  <form name="contact_form" class="contact_form" action="messagedata.php" method="post"  >
    <ul>
        <li>
             <h2>Update/Delete Results</h2>
             
        </li>
        <li>
            <label for="name">Roll:</label>
            <input type="text" name="roll" value="<?php echo $rows ['roll'];?>"/>
			<span class="form_hint"></span>
        </li>

        <li>
            <label for="email">Email:</label>
            <input type="email" name="email" value="<?php echo $rows ['email'];?>" />
            <span class="form_hint"></span>
        </li>
		<li>
            <label for="number">Year:</label>
            <input type="number" name="year" value="<?php echo $rows ['year'];?>" />
            <span class="form_hint"></span>
        </li>
		<li>
            <label for="number">Mobile:</label>
            <input type="number" name="mobile" value="<?php echo $rows ['mobile'];?>" />
            <span class="form_hint"></span>
        </li>
      <li>
            <label for="number">Result:</label>
            <input type="number" name="mobile" value="<?php echo $rows ['result'];?>" />
            <span class="form_hint"></span>
        </li>
     
	 <li>
        	<button class="submit" type="submit">Update!</button>
        
        	<button class="submit" type="submit">Delete!</button>
      </li>
        
    </ul>
</form>

code for: messagedata.php

<?php
include "config.php";

$year=$_POST['year'];
$roll=$_POST['roll'];

$mail=$_POST['email'];
$cell=$_POST['mobile'];
$result=$_POST['result'];<-----Line 74


if($_POST['update'])<--------Line 77
{
$sql="UPDATE `data` SET 

 year='$year',
		  roll='$roll',
		  email='$mail',
		  mobile='$cell',
		  result='$result'
		  
		  WHERE  year='$year'
		  ";
		  if(mysql_query($sql))
		{
			print "<p align=center>Your Datas are updated successfully.</p>";
		}
		else
		{
			print "<p align=center>Your Datas can not be updated.</p>";
		}
}

if($_POST['delete'])<--------Line 100
	{
		$sql="DELETE FROM `data` WHERE year='$year'";
		if(mysql_query($sql))
		{
			echo "Your Data's are Delete Successfully.";
		}
		else
		{
			echo "Your Data's are can not be Delete.";
		}
	}
?>

1st error is whenever I open edit.php a error comes up indicating line 76 bt shows the form & when I select a year for updating the error simply disappears & shows me the data to edit!
Notice: Undefined index: formid in C:\wamp\www\exam1\edit.php on line 76

This means that you cannot open edit.php without setting a year.

Either :

have a page which leads to edit.php which permits the user to pick a year, OR

check for the absence of $_POST[‘formid’] and give it a reasonable value (this year?)


if (!isset($_POST['formid'])){

$kalam = date("Y");

}else{

$kalam = $_POST['formid'];

}

Otherwise your edit.php cannot function without an error, and clearly makes no sense if a year is not set.

That formid value also needs to be filtered to make sure it is within the bounds of what you expect – otherwise you risk an SQL injection attack – from what you have showed us.

Familiarise yourself with FIEO

Thanks! Any help with code 2 error? or can you gimme a better link of a LOGIN & REG form?

Your 2nd error - quite simple.

You have the wrong name for your input field in line 74 - says name=“mobile” when it should say name=“result”.
You have no names assigned to your update and delete buttons so nothing is being passed through to your 2nd page. Assign names to both buttons (name=“update”, name=“delete”).

If you get errors like this in future the first thing to check is that you are getting data posted and to do that, on your second page use

var_dump($_POST);

Which will then show you all your post variables and the data contained within them.

after adding vardump,
messagedata.php shows [array(6) { [“roll”]=> string(4) “1234” [“email”]=> string(20) “ashfee_567@yahoo.com” [“year”]=> string(4) “2010” [“mobile”]=> string(2) “25” [“result”]=> string(1) “6” [“update”]=> string(0) “” } ]

Did everything u said! here is the edit.php code again!

<?php
mysql_connect("localhost", "foodecrp_beta2", "letmeinplz");
mysql_select_db("foodecrp_admin") or die ("Could not select the Database");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Acme it</title>    
    
    <!-- CSS Files -->
    <link href="css/reset.css" rel="stylesheet" type="text/css" media="all" />
    <link href="css/edit.css" rel="stylesheet" type="text/css" media="all" />
	<link href="css/updatebutton.css" rel="stylesheet" type="text/css" media="all" />
	
    <!--[if lte IE 6]>
    <link href="css/ie.css" rel="stylesheet" type="text/css" media="screen" />
    <![endif]-->

	<!-- Javascript -->
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript" src="js/global.js"></script>
</head>

<body>
<!-- begin: wrapper -->
<div id="wrapper">

	<!-- begin: header -->
	<div id="header">
    	<!-- logo --><h1 id="logo"><a href="index.html">Logo</a></h1>
        
        <!-- Main menu -->
		  <ul id="navigation">
            <li ><a href="adminpanel.php">Add New Student</a></li>
            <li ><a href="studentdata.php">Student List</a></li>
            <li><a href="searchdata.php">Search </a></li>	
            <li class="highlighted"><a href="edit.php">Edit</a></li>
        </ul>
		
		
		
		
     
		
        <!-- Right menu -->
        <ul id="fast-links">
      
          <li><a href="logout.php">Log Out</a></li>
        </ul>
        
    <!-- end: header -->
    </div>
	
    <!-- begin: Content Wrapper -->
    <div id="content">
    	
        <!-- begin: Promo Container -->
        <div id="promo-container">
			<h1 class="center">Database Control Panel</h1>
        <!-- end: Promo Container -->
        </div>
		
        <div class="center spacer">
            <h3>Select by "Year" & Change</h3>
            
        </div>
        
       <?php $kalam=$_POST['formid'];  //this is form name=>option select name code.
	   
	   ?>

          <form class="contact_form" name="contact_form" method="post" action="edit.php" name="contact_form">
                    <ul>
					<li>
					<label for="email">Select Year:</label>
					<select name="formid" id="select">
                    <option selected="selected">Year</option>
					</li>
					</ul>		
					
	
	
	<?php
         $sql="SELECT * FROM `data`";
		 $result=mysql_query($sql);
		 while ($rows=mysql_fetch_array($result))
		 {
			 print "<option value=".$rows['year'].">".$rows['year']."</option>";
		 }
	?>
                    </select>
                    
        	<button class="submit" type="submit">Search Now!</button>
       
   </form>

   
   
   
   
    </td>
    
  </tr>
  <?php
  
  $sql=" SELECT * FROM `data` WHERE year='$kalam'";
  $result=mysql_query($sql);
  $rows=mysql_fetch_array($result)
  
  ?>
  
  
  
  <form name="contact_form" class="contact_form" action="messagedata.php" method="post"  >
    <ul>
        <li>
             <h2>Update/Delete Results</h2>
             
        </li>
        <li>
            <label for="name">Roll:</label>
            <input type="text" name="roll" value="<?php echo $rows ['roll'];?>"/>
			<span class="form_hint"></span>
        </li>

        <li>
            <label for="email">Email:</label>
            <input type="email" name="email" value="<?php echo $rows ['email'];?>" />
            <span class="form_hint"></span>
        </li>
		<li>
            <label for="number">Year:</label>
            <input type="number" name="year" value="<?php echo $rows ['year'];?>" />
            <span class="form_hint"></span>
        </li>
		<li>
            <label for="number">Mobile:</label>
            <input type="number" name="mobile" value="<?php echo $rows ['mobile'];?>" />
            <span class="form_hint"></span>
        </li>
      <li>
            <label for="number">Result:</label>
            <input type="number" name="result" value="<?php echo $rows ['result'];?>" />
            <span class="form_hint"></span>
        </li>
     
	 <li>
        	<button class="submit" type="submit" name="update">Update!</button>
        
        	<button class="submit" type="submit" name="delete">Delete!</button>
      </li>
        
    </ul>
</form>
  
  
  
  

        
        <!-- end: Bottom Container -->
        </div>
        
        <!-- Legals and Copyright -->
        <p class="small clear center">© Designed & Developed by Adnan Alvee(Acme IT Ltd) All rights reserved.<br />
        <a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a></p>
        
    <!-- end: Content Wrapper -->
    </div>
    
<!-- end: wrapper -->
</div>

</body>
</html>

Are you still getting the same error messages or having problems (if so, please explain)?

Your post data (apart from the mobile number) looks correct (using var_dump is just to help you finding any errors or missing posted data).

no error shows up actually, just the array message given above but nothing updates actually.
Mind seeing for yourself?, my test program is here beta2.foodiecorp.com, Login with user ‘xem’ & pass as ‘123456’ & you will get the simple CRUD system & here is the update & delete php file coding again!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Platino - Html Template by Stefano Giliberti</title>    
    <link rel="shortcut icon" type="image/ico" href="images/favicon.ico" />
    
    <!-- CSS Files -->
    <link href="css/reset.css" rel="stylesheet" type="text/css" media="all" />
    <link href="css/edit.css" rel="stylesheet" type="text/css" media="all" />
	<link href="css/updatebutton.css" rel="stylesheet" type="text/css" media="all" />
	
    <!--[if lte IE 6]>
    <link href="css/ie.css" rel="stylesheet" type="text/css" media="screen" />
    <![endif]-->

	<!-- Javascript -->
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript" src="js/global.js"></script>
</head>

<body>
<!-- begin: wrapper -->
<div id="wrapper">

	<!-- begin: header -->
	<div id="header">
    	<!-- logo --><h1 id="logo"><a href="index.html">Logo</a></h1>
        
        <!-- Main menu -->
		  <ul id="navigation">
            <li ><a href="adminpanel.php">Add New Student</a></li>
            <li ><a href="studentdata.php">Student List</a></li>
            <li><a href="searchdata.php">Search </a></li>	
            <li class="highlighted"><a href="edit.php">Edit</a></li>
        </ul>
		
		
		
		
     
		
        <!-- Right menu -->
        <ul id="fast-links">
        
<li><a href="logout.php">Log Out</a></li>
        </ul>
        
    <!-- end: header -->
    </div>
	
    <!-- begin: Content Wrapper -->
    <div id="content">
    	
        <!-- begin: Promo Container -->
        <div id="promo-container">
			<h1 class="center">Database Control Panel</h1>
        <!-- end: Promo Container -->
        </div>
		
						<?php
include "config.php";

$year=$_POST['year'];
$roll=$_POST['roll'];

$mail=$_POST['email'];
$cell=$_POST['mobile'];
$result=$_POST['result'];


if($_POST['update'])
{
$sql="UPDATE `data` SET 

 year='$year',
		  roll='$roll',
		  
		  email='$mail',
		  mobile='$cell',
		  result='$result'
		  
		  WHERE  year='$year'
		  ";
		  if(mysql_query($sql))
		{
			print "<p align=center>Your Datas are updated successfully.</p>";
		}
		else
		{
			print "<p align=center>Your Datas can not be updated.</p>";
		}
}

if($_POST['delete'])
	{
		$sql="DELETE FROM `data` WHERE year='$year'";
		if(mysql_query($sql))
		{
			echo "Your Data's are Deleted Successfully.";
		}
		else
		{
			echo "Your Data's are cannot be Deleted.";
		}
	}

var_dump($_POST);  
?>
  
  
  
  

        
        <!-- end: Bottom Container -->
        </div>
        
        <!-- Legals and Copyright -->
        <p class="small clear center">© Designed & Developed by Adnan Alvee(Acme IT Ltd) All rights reserved.<br />
        <a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a></p>
        
    <!-- end: Content Wrapper -->
    </div>
    
<!-- end: wrapper -->
</div>

</body>
</html>