Jump to content

Recommended Posts

Hi Guys

 

Im running PHP V5, and using n Mysql DB, o and its running on apache.

 

Im very new to php but are unfortunatly forced by my employer to deliver a product developed in it. I would really like to ask for you guys to assist me with a specific problem that Im currently experiencing. I currently have a web page that contains a table. This table is being populated/created from a mysql DB. It contains 4 columns. The first is a Unique ID (very important, as this is the value I want). The second is the Description, the third is a tick box. The forth is not relevant.

 

At the bottom of the page I have a delete button.

 

I want to give the user the ability to select multiple tick boxes and press the Delete button, This needs to get the Unique ID (1st columns) value and then be submitted via a SQL query to the DB and then delete it from the DB. How ever I have no Idea how to get the values that are select and fomulate the Query dependent on the amount of items.

 

Can someone please assist me. I have posted the code that Im currently using to create/populate the table.

 

Thanx for any help in advance I really appreciate it.

 

 

<?php

$sql = "SELECT customer_id, customer_description FROM customer order by customer_id desc";

$result = mysql_query($sql);

$counter = 0;

while ($row=mysql_fetch_row($result))

{

if ($counter % 2)

{

$BColour = "FAFAFA";

}

else

{

$BColour = "EFEFEF";

}

 

$counter = $counter + 1;

 

echo "<tr bgcolor='#$BColour'>";

echo "<td>";

echo $row[0];

echo "</td>";

echo "<td>";

echo $row[1];

echo "</td>";

echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='check" . $row[5] . "' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>";

echo "<td>";

echo '<a href="/company/index.php/heading=Customer&action=Edit&customer_id=' . $row[0] . '" style="text-decoration:none;"><span>Edit</span></a> ';

echo "</td>";

echo "</tr>";

 

}

 

 

?>

 

 

 

 

 

Try this

First put your table in a form

 

Change

  echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='check" . $row[5] . "' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>";

to

  echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='entry' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>";

 

 

and add

<input type='submit' value='Delete' />

on the end

 

On php's side

<?php
if (isset($_POST['delete']))
{is_array($_POST['entry']))
   {foreach ($_POST['entry'] as $id)
      {$sql = "DELETE FROM customer_order WHERE id='$id'";
       $query = mysql_query($sql);
      }
  }
}

?>

 

.. Hope this helps :)

Thanx for the help thus far Im starting to see how it fits in the big picture LOL : 0

 

I have a syntax problem though. I get

 

Parse error: syntax error, unexpected '{'

 

at the following place

 

{foreach ($_POST['entry'] as $id)

 

I know it sounds stupid but I have tried to fiddle with it a little but cant seem to solve the problem? It looks right in my eyes, but maybe Im going blind?  :shrug:

 

Can you perhaps tell me why its moaning about the { ?

This line should be:

  echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='entry[]' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>";

 

And the PHP should be.

<?php
if (isset($_POST['delete'])){
  if(is_array($_POST['entry'])) {
     foreach ($_POST['entry'] as $id) {
       $sql = "DELETE FROM customer_order WHERE id='$id'";
       $query = mysql_query($sql);
      }
    }
}

?>

 

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.