Jump to content

deleting a row in a php table?


Gazz1982

Recommended Posts

My php with mysql generates:

 

Delete

Name

Address

[] Checkbox

Bob

Down Town

[] Checkbox

Dave

Down Town

[] Checkbox

Tim

Down Town

For the Checkbox:

  echo "<td><form class='small' name='login' method='post'";
  echo "<input type='checkbox' name='Add' value='yes' /></td>";

 

I want to add 'yes' to my dispose column in my database, how do I update the database to the row which the checkbox is? ie If i check the box next to bob I want to add 'yes' to the dispose column only for Bob

 

The checkboxes are generated through a loop so all will have the same name

 

the mysql table as a unique id auto_increment primary key;

 

Thanks for any help

Link to comment
Share on other sites

ok looks like what i need

 

echo "</table>";
echo"<br /><br />";
echo "<table border='1'>
<tr>
<th>Delete</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Company</th>
<th>Address1</th>
<th>Address2</th>
<th>Address3</th>
<th>County</th>
<th>Country</th>
<th>Post Code</th>
<th>Phone Number</th>
<th>Validate</th>

</tr>";

while($row = mysql_fetch_array($result2))
  {
  echo "<tr>";
  echo "<td><form class='small' name='login' method='post'>'";
  echo "<input type='checkbox' name='Delete' value='<?php echo  $rows['id']?>' /></p></td>";
  echo "<td>" . $row['NAME_FIRST'] . "</td>";
  echo "<td>" . $row['NAME_LAST'] . "</td>";
  echo "<td>" . $row['EMAIL'] . "</td>";
  echo "<td>" . $row['PASSWORD'] . "</td>";
  echo "<td>" . $row['COMPANY'] . "</td>";
  echo "<td>" . $row['ADDRESS1'] . "</td>";
  echo "<td>" . $row['ADDRESS2'] . "</td>";
  echo "<td>" . $row['ADDRESS3'] . "</td>";
  echo "<td>" . $row['COUNTY'] . "</td>";
  echo "<td>" . $row['COUNTRY'] . "</td>";
  echo "<td>" . $row['POST_CODE'] . "</td>";
  echo "<td>" . $row['PHONE'] . "</td>";
  echo "<td>" . $row['VALIDATE'] . "</td>";
  
  echo "</tr>";
  }
echo "</table>";

 

just trying to figure out this bit - sorry I'm a bit of a novice - all help welcomed

$ids = join (',', $_POST['delID']);
$sql = "DELETE FROM docs WHERE docID IN ($ids)";   
mysql_query($sql);

Link to comment
Share on other sites

ok so now im getting

 

delete    name  ID   

[]          Bob    1

[]          Dave  2

[]          Time  3

 

when the table is created where ID is $del which = $row['ID']

 

The value in the check box is also $del

[] = checkbox

 

so now if I run select * from login where ID = $del it should select all of the ones which were checked ???

 

Am I right or close?

Link to comment
Share on other sites

your form code should be

<?php
echo "<form class='small' name='login' method='post'>'";                // Only ONE form

echo "<table border='1'>
<tr>
<th>Delete</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Company</th>
<th>Address1</th>
<th>Address2</th>
<th>Address3</th>
<th>County</th>
<th>Country</th>
<th>Post Code</th>
<th>Phone Number</th>
<th>Validate</th>

</tr>";

while($row = mysql_fetch_array($result2))
  {
  echo "<tr>";
  
  echo "<input type='checkbox' name='Delete[]' value='{$row['id']}' /></p></td>";     // NOTE the []
  echo "<td>" . $row['NAME_FIRST'] . "</td>";
  echo "<td>" . $row['NAME_LAST'] . "</td>";
  echo "<td>" . $row['EMAIL'] . "</td>";
  echo "<td>" . $row['PASSWORD'] . "</td>";
  echo "<td>" . $row['COMPANY'] . "</td>";
  echo "<td>" . $row['ADDRESS1'] . "</td>";
  echo "<td>" . $row['ADDRESS2'] . "</td>";
  echo "<td>" . $row['ADDRESS3'] . "</td>";
  echo "<td>" . $row['COUNTY'] . "</td>";
  echo "<td>" . $row['COUNTRY'] . "</td>";
  echo "<td>" . $row['POST_CODE'] . "</td>";
  echo "<td>" . $row['PHONE'] . "</td>";
  echo "<td>" . $row['VALIDATE'] . "</td>";
  
  echo "</tr>";
  }
echo "</table>";
echo "</form>";
?>

Link to comment
Share on other sites

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.