Hi guys,
I am working on the php page and I would like to add delete button for each row that the data have been print out in the php page.
Here it is the code:
<?php
session_start();
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'databasename');
$errmsg_arr = array();
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
function clean($var){
return mysql_real_escape_string(strip_tags($var));
}
$username = clean($_GET['user']);
$password = clean($_GET['pass']);
if($username == '') {
$errmsg_arr[] = 'username ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'PASSWORD ID missing';
$errflag = true;
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
echo implode('<br />',$errmsg_arr);
}
else {
$qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'";
$result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());
if(mysql_num_rows($result) > 0) {
$qrytable1="SELECT strings1, strings2, strings3 FROM table1 WHERE username='$username'";
$result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
while ($row = mysql_fetch_array($result1)) {
echo "<p id='strings1'>";
echo $row['strings1'] . "</p>";
echo "<p id='strings2'>";
echo $row['strings2'] . "</p>";
echo "<p id='strings3'>";
echo $row['strings3'] . "</p>";
}
}
}
?>
As I find it easy to add the rows in the database, but I find it difficult to delete the rows that each data have been print out with the same id.
How to add the delete button on php page for each data that have been print out from mysql database?
Any info would be much appreciate.