Hello guys, i'm having an issue with updating the record in my database. everything seems to work well except that whenever i try updating the record via the mysql update procedure, it just returns with no errors and the record is not update. i tried echo'ing the $result to see if there was any messages and it just prints 1.

is there something wrong with my code? thanks in advance and appreciate all the help.

if(isset($_POST['action']) && $_POST['action'] == 'submitform')
{

		$xid			= $_POST['id'];
		$xname		= $_POST['name'];
		$xmobile		= $_POST['mobile'];
		$xextra		= $_POST['extra'];
		$xip     		= $_SERVER['REMOTE_ADDR'];
		$xdate 		= strftime("%Y-%m-%d %H:%M:%S");

		$query_mobile = "SELECT mobile FROM $tbl_rec WHERE mobile = '$xmobile' LIMIT 1";
		$result_mobile = mysql_query($query_mobile) or die(mysql_error());

if (mysql_num_rows($result_mobile)==0) {

mysql_select_db($db_name, $connection);
		
	$insert_query = "UPDATE $tbl_rec SET mobile='".$xmobile."',name='".$xname."',extra='".$extra."',ip='".$xip."',date='".$xdate."' WHERE id='".$_POST['id']."'";
		
	$result = mysql_query($insert_query, $connection) or die(mysql_error());
		// header("location: userlist.php");
	echo $result;
	} else {
		header("location: redirect.php");
		}
	}

A value of 1 when printing $result seems to me that the mysql_query call was successful and returned a TRUE .

You can try using a mysql_affected_rows() after the mysql_query to see how many rows were updated.

Also output your UPDATE statement so you can verify it's what you expect and try running that manually against mysql and see what you get.

$insert_query = "UPDATE $tbl_rec SET mobile='".$xmobile."',name='".$xname."',extra='".$extra."',ip='".$xip."',date='".$xdate."' WHERE id='".$_POST['id']."'";

echo "UPDATE statement = $insert_query<br />";
 
$result = mysql_query($insert_query, $connection) or die(mysql_error());

echo "Affected rows = " . mysql_affected_rows() . "<br />";
echo $result;
Be a part of the DaniWeb community

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