toonz Posted June 29, 2013 Share Posted June 29, 2013 I am trying to update a piece of code, using and editing something similar from another page. What it needs to do is update the ctoon location to 1 when, on the admin control panel, we close a listing on the site's trade board. At this time it has only been deleting the trade record but I am trying to have it update the ctoon record in tbl_users_ctoons first, then delete the trade record. Below is the work in progress, with the lines not yet working commented out and the current lines uncommented. Any help you can give with this would be a HUGE help. Thanks in advance up until now it has only deleted the associated record in tbl_trade based on the del_id.it should also be looking in tbl_trade.trade_toonid (which is a comma delimited field), use the IN function and find all matching values in tbl_users_ctoons.usrctoon_id, and update the location field value to 1 in only those matching records. $delid = $_GET['del_id']; //if($delid > 0 && ( is_array($trade_toonid) && sizeof($trade_toonid) > 0)) { if($delid > 0) { //$user_toons = implode(",", $trade_toonid); //$update_ctoons = "update tbl_users_ctoons set location=1 where ("trade_id={$delid}") and usrctoon_id in ($user_toons)"; //$del = new database(); //$del->myquery($update_ctoons,1); //$del_trade = "delete from tbl_trade where ("trade_id={$delid}")"; //$del = new database(); //$del->myquery($del_trade,1); $del = new database(); $del->where("trade_id={$delid}"); $del->delete("tbl_trade"); header("Location:manage_tradeboard.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/279699-having-a-button-update-2-tables-when-clicked/ Share on other sites More sharing options...
darkfreaks Posted June 30, 2013 Share Posted June 30, 2013 (edited) formatted and debugged your code. let us know if you continue to have problems. $delid = isset($_GET['del_id']) ? $_GET['del_id'] : ''; if($delid > 0 && ( is_array($trade_toonid) && sizeof($trade_toonid) > 0)) { if($delid > 0) { $user_toons = implode(",", $trade_toonid); $update_ctoons = "update tbl_users_ctoons set location=1 where trade_id={$delid} and usrctoon_id in ($user_toons)"; $del = new database(); $del->myquery($update_ctoons,1); $del_trade = "delete from tbl_trade where trade_id={$delid}"; $del = new database(); $del->myquery($del_trade,1); $del = new database(); $del->where("trade_id={$delid}"); $del->delete("tbl_trade"); header("Location:manage_tradeboard.php"); exit(); } } Edited June 30, 2013 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/279699-having-a-button-update-2-tables-when-clicked/#findComment-1438593 Share on other sites More sharing options...
chriscloyd Posted June 30, 2013 Share Posted June 30, 2013 How can you read your structure... $delid = isset($_GET['del_id']) ? $_GET['del_id'] : ''; if($delid > 0 && (is_array($trade_toonid) && sizeof($trade_toonid) > 0)){ if($delid > 0){ $user_toons = implode(",", $trade_toonid); $update_ctoons = "update tbl_users_ctoons set location=1 where trade_id={$delid} and usrctoon_id in ($user_toons)"; $del = new database(); $del->myquery($update_ctoons,1); $del_trade = "delete from tbl_trade where trade_id={$delid}"; $del = new database(); $del->myquery($del_trade,1); $del = new database(); $del->where("trade_id={$delid}"); $del->delete("tbl_trade"); header("Location: manage_tradeboard.php"); //exit(); } } Quote Link to comment https://forums.phpfreaks.com/topic/279699-having-a-button-update-2-tables-when-clicked/#findComment-1438606 Share on other sites More sharing options...
darkfreaks Posted June 30, 2013 Share Posted June 30, 2013 thanks for removing all the extra spaces that stupid formatter puts in it i ran it through phpsandbox on all versions of PHP 5 down to 5.4.3 and there were no syntax errors after i removed the undefined index error from the variable not being checked if it was set or not. and the SQL syntax errors. with the extra double quotes and (). also type mismatch phplint could not compare [string] to (int) fixed this as well. had to take out isset() and use (int) instead. <?php $delid = (int)$_GET['del_id']; if($delid !== 0 && (is_array($trade_toonid) && sizeof($trade_toonid) !== 0)){ if($delid !== 0){ $user_toons = implode(",", $trade_toonid); $update_ctoons = "update tbl_users_ctoons set location=1 where trade_id={$delid} and usrctoon_id in ($user_toons)"; $del = new database(); $del->myquery($update_ctoons,1); $del_trade = "delete from tbl_trade where trade_id={$delid}"; $del = new database(); $del->myquery($del_trade,1); $del = new database(); $del->where("trade_id={$delid}"); $del->delete("tbl_trade"); header("Location: manage_tradeboard.php"); //exit(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/279699-having-a-button-update-2-tables-when-clicked/#findComment-1438617 Share on other sites More sharing options...
trq Posted June 30, 2013 Share Posted June 30, 2013 had to take out isset() and use (int) instead. That will cause an error if $_GET['del_id'] isn't set though. Do you actually know how to program php or are you just here putting peoples code through various linters and code checkers? Quote Link to comment https://forums.phpfreaks.com/topic/279699-having-a-button-update-2-tables-when-clicked/#findComment-1438629 Share on other sites More sharing options...
toonz Posted June 30, 2013 Author Share Posted June 30, 2013 ok, I plugged in the code that darkfreaks posted. it doesnt give any errors on the page, but it doesnt appear to be working. it reloads the page after clicking the button that is tied to the code as it should, but it doesnt delete the record from tbl_trade nor update the records in tbl_users_ctoons. below is the code that is currently attached to the button in it's simplest form (removing my lines that were commented out). it deletes the record from tbl_trade, but doesnt yet have any of the code that would update the other table records first before doing the deletion. $delid = $_GET['del_id']; if($delid > 0) { $del = new database(); $del->where("trade_id={$delid}"); $del->delete("tbl_trade"); header("Location:manage_tradeboard.php"); exit(); } I dont know why the code posted by darkfreaks wasnt working since it looks like it should, but there is something its lacking. it wouldnt even delete the record from tbl_trade. Quote Link to comment https://forums.phpfreaks.com/topic/279699-having-a-button-update-2-tables-when-clicked/#findComment-1438690 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.