Jump to content

How would i add a delete row button to this?


Lee-Bartlett

Recommended Posts

Im not sure how to get this to work, i got the query, i got the database echoing all results, i just wanna add one more feild giving me the option of deleting that row.

 

heres the code,

 

<?php  require_once("includes/db_connection.php"); ?>


<?php
$id = $_POST['id']; 
$name = $_POST['name']; 
$email = $_POST['email']; 
$buissnes_name = $_POST['buissnes_name']; 
$location = $_POST['location']; 
$type = $_POST['type']; 

  $delete = mysql_query("DELETE FROM tblbasicform WHERE name='$name'"); 
  

$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());

echo "<table border=2>";
echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td> </tr>";
while($row = MYSQL_FETCH_ARRAY($res))
{

echo "<tr><td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['buissnes_name']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['type']."</td></tr>";
}
echo "</table><br>";
?>

<a href="userform.php">Submit a WIFI hotspot</a>

If I got you right, this should be what you're looking for:

 

<?php  require_once("includes/db_connection.php"); ?>


<?php

if(isset($_POST['name']))
{
	$name = $_POST['name'];
	//If this is not some admin page, validation must be added here!! (Anti SQL injection)
	//Also, the name column should hold unique values... I think it'd be better off using the id column for the query but that's your choice
	$delete = mysql_query("DELETE FROM tblbasicform WHERE name='$name'"); 
}

$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());

echo "<table border=2>";
echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete?</td></tr>";
while($row = MYSQL_FETCH_ARRAY($res))
{

echo "<tr><td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['buissnes_name']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['type']."</td>";
echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">
<input type="hidden" name="name" value="'.$row['name'].'"><input type="submit"></form></td></tr>';
}
echo "</table><br>";
?>

<a href="userform.php">Submit a WIFI hotspot</a>

 

I've added a few notes as comments inside the code. Check them out.

 

Orio.

I must be missing somthing here, i tried to edit that so it deletes by ID instead. did i miss somthing ?

 

<?php  require_once("includes/db_connection.php"); ?>


<?php

if(isset($_POST['id']))
{
	$id = $_POST['id'];

	$delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); 
}

$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());

echo "<table border=2>";
echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete?</td></tr>";
while($row = MYSQL_FETCH_ARRAY($res))
{
echo "<tr><td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['buissnes_name']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['type']."</td>";
echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">
<input type="hidden" id="id" value="'.$row['id'].'"><input type="submit"></form></td></tr>';
}
echo "</table><br>";
?>

<a href="userform.php">Submit a WIFI hotspot</a>

You replaced the "name" field in the input tag... One replacement too much :)

Should be like this:

 

<?php  require_once("includes/db_connection.php"); ?>


<?php

if(isset($_POST['id']))
{
	$id = $_POST['id'];

	$delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); 
}

$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());

echo "<table border=2>";
echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete?</td></tr>";
while($row = MYSQL_FETCH_ARRAY($res))
{
echo "<tr><td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['buissnes_name']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['type']."</td>";
echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">
<input type="hidden" name="id" value="'.$row['id'].'"><input type="submit"></form></td></tr>';
}
echo "</table><br>";
?>

<a href="userform.php">Submit a WIFI hotspot</a>

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.