zed420 Posted January 14, 2009 Share Posted January 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/ Share on other sites More sharing options...
Zhadus Posted January 14, 2009 Share Posted January 14, 2009 Does it give an error or just not updating? Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737070 Share on other sites More sharing options...
zed420 Posted January 14, 2009 Author Share Posted January 14, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737077 Share on other sites More sharing options...
Zhadus Posted January 14, 2009 Share Posted January 14, 2009 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'? Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737080 Share on other sites More sharing options...
zed420 Posted January 14, 2009 Author Share Posted January 14, 2009 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'? Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737082 Share on other sites More sharing options...
zed420 Posted January 14, 2009 Author Share Posted January 14, 2009 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'? Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737098 Share on other sites More sharing options...
Zhadus Posted January 14, 2009 Share Posted January 14, 2009 The first one is blank because it's still failing the IF statement. Keep in mind == is case sensitive, do you have a test page up I can look at? Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737104 Share on other sites More sharing options...
Ninjakreborn Posted January 14, 2009 Share Posted January 14, 2009 Also utilize the "mysql_error" function in order to get the errors to return. This will help narrow down the problems. Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737116 Share on other sites More sharing options...
Zhadus Posted January 14, 2009 Share Posted January 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-737118 Share on other sites More sharing options...
zed420 Posted January 16, 2009 Author Share Posted January 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140823-update-query-not-working/#findComment-738378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.