Jump to content

Update query NOT working


zed420

Recommended Posts

Hi All

Can someone please tell me why this First query doesn't work. Second query and every thing else is fine no errors. I know its set cust_address = 'Cancellation Acknowledged' twice but that's how I need it. Some help will be much appreciated.

$job_id= $_POST["job_id"];
$cust_address= $_POST["cust_address"];


	if($_POST['submit']) {
	foreach($_POST as $job_id) { 

if($_POST["cust_address"] == 'Cancellation Acknowledged'){
	mysql_query("UPDATE job_tb
   		SET job_tb.cust_address = 'Cancellation Acknowledged'
	WHERE job_tb.job_id = '$job_id'")or die(mysql_error());
	if (mysql_affected_rows() > 0) { 
    	print "<font color=red size=2> No. = $job_id has been Updated</font><p>";
	?><script>document.location.href='jobCancel.php'</script><?
	}
}else{
	mysql_query("UPDATE job_tb
   		SET job_tb.cust_address = 'Cancel'
	WHERE job_tb.job_id = '$job_id'")or die(mysql_error());
	if (mysql_affected_rows() > 0) { 
    	print "<font color=red size=2> No. = $job_id has been Updated</font><p>";
	?><script>document.location.href='jobCancel.php'</script><?
  		} 
}
}
}else
		if($name = $_SESSION['name'])   {

$query1 = "SELECT * FROM user, job_tb  WHERE username = '$name' ORDER BY job_id DESC";
$result1 = mysql_query($query1)
       or die ("Couldn't execute query for collecting your data.");
?>
<form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<div class="smallerText">
<TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#CCCCCC">
<TR bgcolor="#FFFFCC" align="center">
<td width="10%"><font color=red><b>Job No.</b></font></TD>
<td width="15%"><font color=red><b>Date/Time</b></font></TD>
<td width="15%"><font color=red><b>Name</b></font></TD>
<td width="25%"><font color=red><b>Pick up Address</b></font></TD>
<td width="20%"><font color=red><b>Destination</b></font></TD>
<td width="20%"><font color=red><b>Booking Type</b></font></TD>
<td width="2%"><font color=red><b>Check</b></font></TD>
</tr>
<?

	while ($row = mysql_fetch_array($result1))  {
    extract($row);
	echo "<tr >
	<td>" . $row['job_id'] . "</td>
	<td>" . $row['dateTime'] . "</td>
	<td>" . $row['cust_name'] . "</td>
	<td>" . $row['cust_address'] . "</td>
	<td>" . $row['des'] . "</td>
	<td>" . $row['typeOfbooking'] . "</td>
<td>" ?>
<input type="checkbox" name="<?=$row[job_id]?>" id="<?=$row[job_id]?>" value="<?=$row[job_id]?>"/>
<? "</TD>
	</tr>";
}
  }
?></table></div>

 
<center><input name="submit" type="submit" value="Cancel Normal Job"/></center>

Thanks

Zed

 

Link to comment
Share on other sites

Thanks for your quick reply

It just wont update, like I said before  the second query works fine which is

                mysql_query("UPDATE job_tb
   		SET job_tb.cust_address = 'Cancel'
	WHERE job_tb.job_id = '$job_id'")or die(mysql_error());
	if (mysql_affected_rows() > 0) { 
    	print "<font color=red size=2> No. = $job_id has been Updated</font><p>";
	?><script>document.location.href='jobCancel.php'</script><?

 

the problem I'm having with is this bit

if($_POST["cust_address"] == 'Cancellation Acknowledged'){
	mysql_query("UPDATE job_tb
   		SET job_tb.cust_address = 'Cancellation Acknowledged'
	WHERE job_tb.job_id = '$job_id'")or die(mysql_error());
	if (mysql_affected_rows() > 0) { 
    	print "<font color=red size=2> No. = $job_id has been Updated</font><p>";
	?><script>document.location.href='jobCancel.php'</script><?

 

Does it give an error or just not updating?

Link to comment
Share on other sites

If that one is updating, that means this line:

if($_POST["cust_address"] == 'Cancellation Acknowledged'){

Has failed, if you echo $_POST["cust_address"] on the screen (just for debugging purposes) does it give you 'Cancellation Acknowledged'?

Link to comment
Share on other sites

I'll try that give 5min

If that one is updating, that means this line:

if($_POST["cust_address"] == 'Cancellation Acknowledged'){

Has failed, if you echo $_POST["cust_address"] on the screen (just for debugging purposes) does it give you 'Cancellation Acknowledged'?

Link to comment
Share on other sites

Yes it gives me 'Cancellation Acknowledged' when I echo it. I've tried to echo the query the first one is blank the second one give you the out put. Why is first one blank?? any ideas

if($_POST['submit']) { 
        foreach($_POST as $job_id) {  
         
if($_POST["cust_address"] == 'Cancellation Aknowledged'){ 
    $query = "UPDATE job_tb SET cust_address = 'Cancellation Acknowledged' 
    WHERE job_id ='$job_id'"; 
    echo "$query"; 
    $result = mysql_query($query) 
    or die ("Couldn't execute query for collecting your data."); 
            }else{ 
            $query = "UPDATE job_tb SET cust_address = 'Cancel' 
            WHERE job_id ='$job_id'"; 
            echo "$query";  
            $result = mysql_query($query) 
            or die ("Couldn't execute query for collecting your data."); 
        } 
    } 
}else 

I'll try that give 5min

If that one is updating, that means this line:

if($_POST["cust_address"] == 'Cancellation Acknowledged'){

Has failed, if you echo $_POST["cust_address"] on the screen (just for debugging purposes) does it give you 'Cancellation Acknowledged'?

Link to comment
Share on other sites

Also utilize the "mysql_error" function in order to get the errors to return. This will help narrow down the problems.

 

From what he is describing, the query isn't failing, it's just not happening, because it fails the PHP IF statement.

I may be mistaken though.

Link to comment
Share on other sites

Just like to say Thank you to all, this is what I ended up with and works.

 

if($_GET['cust_address'] == 'Cancelled'){
error_message("This Job has already been Cancelled");
}else 

if($_GET['cust_address'] == 'Cancel'){
error_message("Please wait Dispatcher is processing this Cancellation");
}else 

if($_GET['cust_address']){
mysql_query("UPDATE job_tb
SET job_tb.cust_address = 'Cancel'
WHERE job_tb.job_id = '$job_id'")or die(mysql_error());
if (mysql_affected_rows() > 0) { 
?><script>document.location.href='Test.php'</script> <?
  } 
}

 

Thank you

Zed

 

Also utilize the "mysql_error" function in order to get the errors to return. This will help narrow down the problems.

 

From what he is describing, the query isn't failing, it's just not happening, because it fails the PHP IF statement.

I may be mistaken though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.