Heyy guys, need some help here...the thing i'm suppose to do is, update a value for a single row, but currently its updating the value for all the row...

<?php
session_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="testing3"; // Table name

$invoice_no=$_SESSION['invoice_no'];
$container_no=$_SESSION['container_no'];
$pnum=$_POST['pnum'];
$sernum=$_POST['sernum'];
$sprtnum=$_POST['sprtnum'];
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die(mysql_error());

$sql1="SELECT * FROM $tbl_name WHERE invoice_no = '$invoice_no' and container_no = '$container_no' and prt_no ='$pnum' and ser_no='$sernum' and sprt_no='$sprtnum'";
$result1 = mysql_query($sql1);
$row1 = mysql_num_rows($result1);
$row2 = mysql_fetch_array($result1);

$invoice_no1=$row1['invoice_no'];
$container_no1=$row1['container_no'];
$prt_no=$row2['prt_no'];
$ser_no=$row2['ser_no'];
$sprt_no=$row2['sprt_no'];
$status=$row2['status'];

echo "$sernum";

if($row1>0)
{
	if($invoice_no1=$invoice_no && $container_no1=$container_no && $part_no=$pnum && $sprt_no=$sprtnum && $ser_no=$sernum){ 
		if($status=='Completed')
		{
			echo "Item has been scanned before";
			//header("refresh:1;url=scan.php");
		}
		else
		{
		$sql2="UPDATE $tbl_name SET status='Completed' WHERE $ser_no=$sernum";
		$result2=mysql_query($sql2);
		echo "Shipment Verified";
		//header("refresh:1;url=scan.php");
		}
		}
	else
	{
		echo "Wrong input, please try again";
		//header("refresh:1;url=scan.php");
	}
}
else
{
	echo "Error, shipment not found....Please relog";
	//header("refresh:1;url=main_login.php");
}
	
?>

You have an incorrect $ in your update query and no quote marks around your variable

$ser_no=$sernum

Coorect:

$sql2="UPDATE $tbl_name SET status='Completed' WHERE ser_no='".$sernum."'";

owh, i see....thank you soo much...its working now....owe you one....thank u again...

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.