0

heyy guys...really could use some help here...
my table is not updating its value, but there are no errors...the syntax seem to be correct

<?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'];
// 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'";
$result1 = mysql_query($sql1);
$row1 = mysql_num_rows($result1);
$row2 = mysql_fetch_array($result1);

$part_no=$_SESSION['part_no'];
$spart_no=$_SESSION['spart_no'];
$no_pallets=$_SESSION['no_pallets'];
$pnum=$_POST['pnum'];
$sernum=$_POST['sernum'];
$sprtnum=$_POST['sprtnum'];

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

echo "$invoice_no"."<br>";
echo "$container_no"."<br>";
echo "$invoice_no1"."<br>";
echo "$container_no1"."<br>";
echo "$prt_no"."<br>";
echo "$ser_no"."<br>";
echo "$sprt_no"."<br>";
echo "$pallet_no"."<br>";

if($row1>0)
{
	if($invoice_no1==$invoice_no && $container_no1==$container_no && $part_no==$pnum && $ser_no==$sernum && $sprt_no==$sprtnum){ 
		$sql2="UPDATE $tbl_name SET 'status'='Completed' WHERE 1";
		$result2=mysql_query($sql2);
		echo "Shipment Verified";
		}
	else
	{
		echo "Wrong input, please try again";
	}
}
else
{
	echo "Error, shipment not found....Please relog";
	//header("refresh:1;url=main_login.php");
}
	
?>
3
Contributors
9
Replies
10
Views
5 Years
Discussion Span
Last Post by gopi17
0

I am not sure of the "1" in the WHERE clause of the update query. I am not sure what row the query is supposed to match to perform the update.

0

yea...but as you can see, i've already specify the conditions in the if-else statement...it will return true right?

0

In the IF conditional statements you are ensuring that certain criterion are true before attempting to update the the database row. But your query itself needs to specify which row to update. In this case I am assuming that each row will have a unique number in the invoice number in which cause the WHERE clause could be WHERE invoice_number='$invoice_number'. This will tell your MySQL database to change the status field in the row that belongs to that invoice number.

The fact that you didn't get an error could generally mean that there is technically no error in your query but nothing is actually updated because your query doesn't tell it which row to update. At least from what I can tell anyway.

0

okay...i changed it...

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

invoice_no will be repeating, ser_no is unique....its still the same...any idea

Edited by gopi17: n/a

0

weekendrockstar thank you for your help...its working now....i did something like this...

if($invoice_no1=$invoice_no && $container_no1=$container_no && $part_no=$pnum && $sprt_no=$sprtnum){ 
		$sql2="UPDATE $tbl_name SET status='Completed' WHERE $ser_no=$sernum";
		$result2=mysql_query($sql2);
		echo "Shipment Verified";
		}
	else
	{
		echo "Wrong input, please try again";
	}

guess its because of the "=="....thank you again

0

Is the value of $ser_no a name of a column in this table? In the WHERE clause you need to specify a column where the unique data (such as an ID number) is stored and have it equal the specific serial number. Like if the column that holds the serial numbers is named 'serial' I would do:

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

So if the serial number for the order you're working with were 12345 then it would update the the column named status to Completed for the row where the value in the serial field equals 12345.

I removed the single quote from the declaration of the status field because you are declaring it directly by name. I removed an "=" from the WHERE clause and added single quotes around $sernum.

Still not positive that it'll fix the whole problem but they should be steps in the right direction.

0

Ahh good! I missed your post about figuring out while typing my last one. Since it works disregard the rest of my previous post but I'm glad to see that a suggestion in the post did seem to fix it.

You can set this thread to "solved" if you're satisfied.

0

Mark this thread as solved if your problem solved.

Dont use this quotes for field_name like 'status'. if you need, you can use like this `status`

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.