LinkShare  Referral  Program

New

Advertise ad Here
learn more
            PHP > Beginner PHP-MySql tutorial
Added on   15.11.09
Clicks     1169
Rating:   5.00   out of 5 from   2   raters      
         rate this page   
 Not rated yet.Be the first one to vote!!

iBuyOfficesupply.com Inc. There is not Comments for this Article,Be the first one
Ask any relevant question in the Comments or leave your valuable feed-back

printer  Print version of this article

star  Add it to your favourite!

mail email this page to a frend
LinkShare  Referral  Program

Beginners PHP-MySql Tutorial



 MySql Deleting Data

    We have seen how to insert, select and retrieve ,update data, now it's time to learn how to delete unwanted data fromyour table,just have a look at the following table :

    ID Title Author Category Price
    11 Advanced Database Technology and Design Mario Piattini and Oscar Diaz Database, ,$ 89.00
             

    If you had to delete this row ,here is the code

    ?php
    $host = "localhost"; // your host name
    $username = "root"; // your user name to access MySql
    $password = "prccn5021"; // your password to access MySql
    $database = "db_guestbook"; // The name of the database

    //$link = mysql_connect($host,$username,$password);
    if (!$link  = @mysql_connect($host,$username,$password,true))
    {die('Could not connect:'. mysql_error()); }

    @mysql_select_db($database) or die( "Unable to select database");


    //echo $rows_affected;  

    $sql="DELETE FROM books WHERE title='Advanced Database Technology and Design '" ;


    $result = mysql_query($sql);
    if (!$result) {
    die('Invalid query: ' . mysql_error());
    }
    $rows_affected =mysql_affected_rows();
    echo $rows_affected;
    ?>

    The only difference from this code to the one to update is the $sql variable,therefore I don't need to explain the code,this time,and this is the end of this Beginners Tutorial,obviously all this won't pretend to turn you into a PHP guru but just give you a basic knowledge of what you may do with PHP and MySql.

    I hope you enjoyed.