Jump to content

[SOLVED] Deleting rows in db


Lee-Bartlett

Recommended Posts

Ok so i want to try minipulate my update code and im not completly sure where i might be going wrong, This code makes a drop down boxs, and pulls the names from my database. So i made a include file which didnt work but am i going down the right track to do this? Wanna do a simple, click on drop down, get name, click go and it deletes that row.

 

codes are

 

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


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

echo "<form action=\"\" method=\"post\">";
echo "<select name=\"name\">";

while($row = mysql_fetch_array($res)){

echo "<option>". $row['name'];
        echo "</option>";
$name = $row['name'];
    $email = $row['email'];
    $location = $row['location'];
$buissnes_name = $row['buissnes_name'];
$type = $row['type'];
  }
echo "</select><br>";
echo "<input type=submit value=\"go\">";
echo "</form>";

include("delete.php");

?>

 

delete.php now

 

<?php
if($_GET["name"]=="delete")
{
    $sql = "DELETE FROM news WHERE name=$name";
    $res = mysql_query($sql);
    echo "Row deleted!";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/126957-solved-deleting-rows-in-db/
Share on other sites

Quite a few issues. First, you're using the POST method in your form, but trying to use GET in your delete.php. Second, you're not assigning values to your <option> tags (like <option value='somevalue'>). Third, you are checking to see if $_GET['name'] (should be $_POST) is set, but then assuming that $name will be equal to $_GET (this can work if the server is set up properly). Finally, you're checking if your submitted value is equal to "delete," which it will not be.

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.