3 Replies - 188 Views - Last Post: 02 August 2012 - 09:31 AM Rate Topic: -----

#1 airy  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 22
  • Joined: 11-July 12

Delete from database upon action selected

Posted 02 August 2012 - 08:52 AM

Anyone know what to write to delete the whole row of particular id at datbase

case 'delete':
		if ($cart) {
			$items = explode(',',$cart);
			$newcart = '';
			foreach ($items as $item) {
				if ($_GET['id'] != $item) {
					if ($newcart != '') {
						$newcart .= ','.$item;
					} else {
						$newcart = $item;
					}
				}
			}
			$cart = $newcart;
		}


Is This A Good Question/Topic? 0
  • +

Replies To: Delete from database upon action selected

#2 no2pencil  Icon User is online

  • Original Digital Gansta
  • member icon

Reputation: 4466
  • View blog
  • Posts: 24,917
  • Joined: 10-May 07

Re: Delete from database upon action selected

Posted 02 August 2012 - 08:55 AM

Deleting from the database is a lot more dangerous than marking items as non-active. But if you must, you shouldn't EVER plug GET array variables into your sql string. But if you must do that, you can use the following :

delete from table_name where id='$_GET[id]';

Though I would recommend you learn from the provided statement, & do it safely & correctly.
Was This Post Helpful? 0
  • +
  • -

#3 airy  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 22
  • Joined: 11-July 12

Re: Delete from database upon action selected

Posted 02 August 2012 - 09:03 AM

so how do i use that in the following codes?


<td><?echo '<br /><a href="cart.php?action=delete&id='.$row['pd_id'].'">Remove</a></li>';?></td>

Was This Post Helpful? -1
  • +
  • -

#4 no2pencil  Icon User is online

  • Original Digital Gansta
  • member icon

Reputation: 4466
  • View blog
  • Posts: 24,917
  • Joined: 10-May 07

Re: Delete from database upon action selected

Posted 02 August 2012 - 09:31 AM

Since I have to guess at your database layout, I would assume that $row['pd_id'] your defining id for the row, so :

delete from table_name where id='$row[pd_id]';

If that isn't correct, we need to see how your database is setup.

Quote

Though I would recommend you learn from the provided statement, & do it safely & correctly.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1