Page 1 of 1
Access to MySQL database through normal php webpage?
Posted: Wed Sep 06, 2006 4:05 pm
by ecopetition
I've just developed a web page, which allows me to view data which is in a MySQL database table straight form the page.
However, i want to see if i can take this one step further.
I want to be able to delete entries into this database from this same page. Does anyone have a suggestion?
Thank you for helping a newbie

Posted: Wed Sep 06, 2006 4:09 pm
by s.dot
You will need an HTML form to select which record(s) you want to delete. And send the action of the form to a PHP script that will perform the SQL query(ies).
Posted: Wed Sep 06, 2006 4:12 pm
by ecopetition

I wish I could understand. The problem is, is that although I can build CSS and HTML pages, i suck when it comes to MySQL and PHP. Can you explain more fully?
Posted: Wed Sep 06, 2006 4:14 pm
by andym01480
phpmyadmin has a neat look for that.
Each row of your table will be a row from the database with a unique id lets call it item_id (assuming your table has an id column autoincrementing!)
In your table of results have a column with links that goes to say deleterecord.php?item=$item_id
Where $item_id is the id of that record row.
Then in deleterecord.php perform a check that you want it deleted and then delete the record.
Code: Select all
if (isset($_POST[confirm])){//delete record
$id=$_POST[id];
$query="DELETE * from tablename WHERE idname='$id'";
mysql_query($query) or die ("Couldn't delete");
exit("Done");
}
$id1=$_REQUEST['item_id'];
//check right record and confirm delete
$query1="SELECT FROM tablename WHERE idname='$id1'";
$result=mysql_query($query1);
$row=mysql_fetch_assoc($result);
//output row
//form for confirm
echo "Are you sure you want to delete?";
echo "<form action=deleterecord.php method=post>";
echo "<input type=hidden name=id value=$id1>"
echo "<input type=hidden name=confirm value=y><input type=submit>";
Don't forget to make it secure from the general public!!!
Before you play back up the table data in case of a coding mistake - I've deleted every record before now!!!!
EDIT - missed a double quote off the query!
Posted: Wed Sep 06, 2006 4:14 pm
by gf05856
You could use something like
PhpMyEdit
Which does something like :
phpMyEdit generates PHP code for displaying/editing MySQL tables in HTML. All you need to do is to write a simple calling program (a utility to do this is included). It includes a huge set of table manipulation functions (record addition, change, view, copy, and removal), table sorting, filtering, table lookups, and more.
Posted: Wed Sep 06, 2006 4:23 pm
by s.dot
hmm very generally speaking
HTML Form
Code: Select all
<form action="delete_record.php" method="post">
<input type="text" name="record_to_delete" />
<input type="submit" value="Delete Record" />
</form>
delete_record.php
Code: Select all
<?php
if(!empty($_POST['record_to_delete']))
{
mysql_query("DELETE FROM `table` WHERE `id` = '".$_POST['record_to_delete']."'") or die(mysql_error());
}
?>
it's a start

Posted: Thu Sep 07, 2006 10:26 am
by ecopetition
Thanks for your help
