Adding data to a Database
This is our last part , we have added links to our
database and we have displayed these links but damn
there are some incorrect links and we need to delete
, no problem we will guide you through this .
In this script we will again create a form in which
the user/admin enters the link and this is then deleted
from the database , if no data is entered then a message
is displayed . We could also have deleted links by using
their id values but we would probably keep that as an
admin function , this example is more for the likes
of say a user submitted links site like www.aspin.com
for example.
Here is the code for the form , again nothing tricky
here.
<form action="deletingfromadb1.php" method
="POST">
<input type = "text" name = "delete"
maxlength="50"><br>
<input type = "submit" value = "delete
link"><br>
</form>
Now for the script which in this case is called deletingfromadb1.php
, remember and add your own details instead of the following
section ("hostname","username" ,"password")
<?php
//make our connection details
$connection = mysql_connect("hostname","username"
,"password")
or die ("Cannot make the connection");
//connect to sampledb with our connection details
$db = mysql_selectdb("sampledb" , $connection)
or die ("Cannot connect to the database");
//if the text field wasnt blank enter data
if($delete)
{
//insert the text box data into the sample table
$sql_query = "DELETE FROM sample WHERE link = ('$delete')";
$result = mysql_query($sql_query);
//display the entered link
echo "You entered the following info " . $delete;
echo "<a href='testingourdb.php'>Back to
test page</a>";
}
//if it was display a message
else
{
echo ("you didnt enter any data");
}
?>
|