Hello there, I'm having a problem on this one. I want to update my records, but when I click save, the specific fields/record is null. instead of updating/edit.

These is my PHP code for admin_view.php (This is the form where you can choose a specific record/field that you are going to update.)

<form id="form1" name="form1" method="post" action="">
      <?php
			include("connect-db.php");
			
				
			$result=mysql_query("SELECT * FROM emprofile");
		
			echo "<table border='5' cellpadding='10' align='center'>";
        	echo "<tr> 
			<th>Month</th> 
			<th>Employee No</th> 
			<th> Employee Name</th>
			</tr>";
			
			while($test = mysql_fetch_array($result))
			{
				$id = $test['number'];	
				echo "<tr align='center'>";	
				echo"<td><font color='black'>" .$test['Month']."</font></td>";
				echo"<td><font color='black'>" .$test['Employeeno']."</font></td>";
				echo"<td><font color='black'>". $test['Employeename']. "</font></td>";
				echo"<td> <a href ='admin_edit.php?number=$id'>Edit</a>";
				echo "</tr>";
			}
			mysql_close($connection);
			?>
    </form>

This is my PHP code in admin_edit.php (This is the form where the admin can update/edit a record)

<?php
require("connect-db.php");
$id =$_REQUEST['number'];

$result = mysql_query("SELECT * FROM emprofile WHERE number = '$id'");
$test = mysql_fetch_array($result);
if (!$result) 
		{
		die("Error: Data not found..");
		}
				$month=$test['Month'] ;
				$empno= $test['Employeeno'] ;					
				$empname=$test['Employeename'] ;
				$salary=$test['Salary'] ;
				$allottee=$test['Allottee'] ;
				$relation= $test['Relation'] ;					
				$sss1=$test['sss'] ;
				$ph1=$test['ph'] ;
				$pagibig1=$test['pagibig'] ;
				$tax1= $test['tax'] ;					
				$total1=$test['total'] ;
				$sss2=$test['sss2'] ;
				$ph2=$test['ph2'] ;
				$pagibig2=$test['pagibig2'] ;
				$tax2= $test['tax2'] ;					
				$total2=$test['total2'] ;
				$tded=$test['totaldeduction'] ;
				$tsal= $test['totalsalary'] ;					
				$allotment=$test['allotment'] ;
				

if(isset($_POST['save']))
{	
	$month_save = $_POST['Month'];
	$empno_save = $_POST['Employeeno'];
	$empname_save = $_POST['Employeename'];
	$salary_save = $_POST['Salary'];
	$allottee_save = $_POST['Allottee'];
	$relation_save = $_POST['Relation'];
	$sss1_save = $_POST['sss'];
	$ph1_save = $_POST['ph'];
	$pagibig1_save = $_POST['pagibig'];
	$tax1_save = $_POST['tax'];
	$total1_save = $_POST['total'];
	$sss2_save = $_POST['sss2'];
	$ph2_save = $_POST['ph2'];
	$pagibig2_save = $_POST['pagibig2'];
	$tax2_save = $_POST['tax2'];
	$total2_save = $_POST['total2'];
	$tded_save = $_POST['totaldeduction'];
	$tsal_save = $_POST['totaldeduction'];
	$allotment_save = $_POST['totaldeduction'];

	mysql_query("UPDATE emprofile SET Month='$month_save', Employeename='$empname_save', Salary='$salary_save', Allottee='$allottee_save', Relation='$relation_save', sss='$sss1_save', ph='$ph1_save', pagibig='$pagibig1_save', tax='$tax1_save', total='$total1_save', sss2='$sss2_save', ph2='$ph2_save', pagibig2='$pagibig2_save', tax2='$tax2_save', total2='$total2_save', totaldeduction='$tded', totalsalary='$tsal', allotment='$allotment' WHERE number = '$id'")or die(mysql_error()); 
	echo "Saved!";
	
	header("Location: admin_view.php");			
}
mysql_close($connection);
?>

Anyone can help me? Thank you

your admin_edit.php is confusing. How can you edit the values, if you dont have them posted in a form values? You just have, click edit, then variables to straight to the database with no option of editing? Second you have

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

again, no in a form, so how can you post using the save button?

$result = mysql_query("SELECT * FROM emprofile WHERE number = '$id'");

to

$result = mysql_query("SELECT * FROM emprofile WHERE number = '" . $id . "'");

Also is number an int or string, if int remove single quotes.

Also is number an int or string, if int remove single quotes.

Works with and without for an int, and there is no need for splitting the string like that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.