(PHP) - Creating a delete row script?

Caporegime
Joined
3 Jan 2006
Posts
25,264
Location
Chadderton, Oldham
Hi, I have created a script to retrieve information from the database and to enter information, I have then created a script that goes on a new page that will edit the information of the existing rows then on submit redirect to the main page.

Below is the code for the page that edits the existing rows.

Code:
$results = $dbh->prepare('SELECT * FROM details WHERE id = :id');
$results->execute(array(
    ':id' => $_GET['id']));

if (isset($_POST['submit'])) header("Location: http://bza410.teaching.mysalford.biz/workshop/home.php"); {

    $update = $dbh->prepare('UPDATE details SET firstname = :firstname, surname = :surname, houseno = :houseno, street = :street, town= :town,
           county = :county, postcode = :postcode,  mobile = :mobile, nickname = :nickname, website = :website,
           homephone = :homephone WHERE id=:id');
    $update->execute(array(
        ':id' => $_POST['id'],
        ':firstname' => $_POST['firstname'],
        ':surname' => $_POST['surname'],
        ':houseno' => $_POST['houseno'],
        ':street' => $_POST['street'],
        ':town' => $_POST['town'],
        ':county' => $_POST['county'],
        ':postcode' => $_POST['postcode'],
        ':mobile' => $_POST['mobile'],
        ':nickname' => $_POST['nickname'],
        ':website' => $_POST['website'],
        ':homephone' => $_POST['homephone']
    ));
}

$pagetitle = 'Welcome to ENSI';
require 'template/header.php';

$row = $results->fetch()
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
        <legend>Details</legend>
        <input type="hidden" name="id" value ="<?php echo ($row ['id']); ?>" />
        <label>First Name:</label>
        <input type="text" name="firstname" value ="<?php echo ($row ['firstname']); ?>" />
        <br/>
        <label> Surname:</label>
        <input type="text" name="surname" value ="<?php echo ($row ['surname']); ?>" />
        <br/>
        <label> House name/number </label>
        <input type="text" name="houseno" value ="<?php echo ($row ['houseno']); ?>" />
        <br/>
        <label> street </label>
        <input type ="text"  name ="street" value ="<?php echo ($row ['street']); ?>"/>
        <br/>
        <label> town/city </label>
        <input type ="text "  name ="town" value ="<?php echo ($row ['town']); ?>"/>
        <br/>
        <label> county </label>
        <input type =" text" name ="county" value ="<?php echo ($row ['county']); ?>" />
        <br/>
        <label> post code </label>
        <input type="text" name="postcode" value ="<?php echo ($row ['postcode']); ?>"/>
        <br/>
        <label>Mobile Phone</label>
        <input type="text" name="mobile" value ="<?php echo ($row ['mobile']); ?>" />
        <br/>
        <label>Nick Name</label>
        <input type="text" name="nickname" value ="<?php echo ($row ['nickname']); ?>" />
        <br/>
        <label>Websites</label>
        <input type="text" name="website" value ="<?php echo ($row ['website']); ?>" />
        <br/>
        <label>Homephone</label>
        <input type="text" name="homephone" value ="<?php echo ($row ['homephone']); ?>" />
        <br/>
        <input type="submit" name="submit" value="submit" />
    </fieldset>
</form>

Is it possible to modify this code which will go on another page for the delete script that will actually work, for a delete script would it be some code that goes like "if delete button is pressed, then delete from database where id = id"

So I need a to use the select statement first to select the id, then I assume if the ID is deleted the My SQL database would just delete all the information anyway when the ID is deleted?



Thanks
Will.
 
Back
Top Bottom