Jump to content

Recommended Posts

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();
}

 

 

 

 

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 by darkfreaks

How can you read your structure... :P

$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();

     }

}

thanks for removing all the extra spaces that stupid formatter puts in it :tease-03:

 

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();

     }

}
?>

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.

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.