We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,901 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Can't update records

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

4
Contributors
3
Replies
6 Days
Discussion Span
1 Year Ago
Last Updated
4
Views
shielaolid
Light Poster
36 posts since Mar 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 0

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?

fobos
Posting Whiz
345 posts since Feb 2009
Reputation Points: 29
Solved Threads: 67
Skill Endorsements: 3

$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.

fpaquin
Newbie Poster
14 posts since Jan 2007
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

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.

pritaeas
Posting Prodigy
Moderator
9,271 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0929 seconds using 2.91MB