Jump to content

Edit Row ... Delete Row?


Kleidi

Recommended Posts

Hello everyone!

 

I'm new on Php and i'm building a mini script for user management with login function. Anyway, i have integrated a adduser script found somewhere and modified for my needs, but now i want to have the possibility to modify and delete options.

I need a code that, when i want to delete a user, should click on a buton linked like this http://domain.tld/admin/users.php?delete=1 where 1 = ID of the user.

 

What i have now is:

 

addusers.php

<?php
session_start();

if(!isset($_SESSION['loggedin'])) {
   header('Location: '.$domain.'index.php?error=1');
   exit();
}
?>
<form method="post" name="shtouser" action="modulet/perdoruesit/p.shtoperdorues.php">

<p><label for="username">Username : <input type="text" name="username" id="username" /></label></p>
<p><label for="password">Passwordi : <input type="password" name="password" id="password" /></label></p>
<p><label for="emri">Emri : <input type="text" name="emri" id="emri" /></label></p>

<p><input class="buton" type="submit" name="submit" value="Shtoje" /> <input class="buton" type="reset" name="reset" value="Rifillo" /></p>
</form>

<?php
if (isset($_GET['error']) AND !empty($_GET['error'])) 
{
    echo 'Error, Please try again.';
}
?> 

 

 

adduser.process.php

<?php
session_start();

if(!isset($_SESSION['loggedin'])) {
   header('Location: '.$domain.'index.php?error=1');
   exit();
}
?>
<?php
include 'E:/Program Files/VertrigoServ/www/live/admini/config.php';

$username = $_POST['username'];
$password = $_POST['password'];
$emri = $_POST['emri'];

$username = Encrypt($username);
$password = Encrypt($password);

$username = safeAddSlashes($username);
$password = safeAddSlashes($password);

$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);

$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);
$sql="INSERT INTO login (`user`, `pass`, `emri`) VALUES ('$username', '$password', '$emri')";
mysql_query($sql, $db) or die('Gabim! Shtimi i citimit deshtoi.');

mysql_close();
ob_start();
header('Location: '.$domain.'admin.php?sukses=1');
ob_flush();

?> 

 

showusers.php

<?php
session_start();

if(!isset($_SESSION['loggedin'])) {
   header('Location: '.$domain.'index.php?error=1');
   exit();
}
?>

<?php
include 'E:/Program Files/VertrigoServ/www/live/admini/includet/dbconfig.php';
include 'E:/Program Files/VertrigoServ/www/live/admini/includet/dblidhja.php';
$query="SELECT * FROM `login` ORDER BY `login`.`ID`";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<br /><br /><center><div class="usershfaq">
<table width="598" border="0" align="center" class="citimekoka">
  <tr>
    <td width="75" class="shfaqid">ID</td>
    <td width="361" class="shfaqemri">Emri</td>
    <td width="140" class="shfaqmodifikime">Modifikime</td>
  </tr>
</table></center>


<?php
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"ID");
$emri=mysql_result($result,$i,"emri");
?>
<center>
<table width="598" border="0">
  <tr>
    <td width="75" class="shfaqid"><?php echo $id; ?></td>
    <td width="361" class="shfaqemri"><?php echo $emri;  ?></td>
    <td width="140" class="shfaqmodifikime">Fshije  -  Modifikoje</td>
  </tr>
</table></center>
    
</div>
<?php
$i++;
}
?> 

 

Now, i need to have a delete button, and a modify option for editing username or password of any user.

Hope that someone can help me.

 

Thank you in advance.

 

P.S. p.shtoperdorues.php = adduser.process.php

Emri = Name - Real Name

Fshije = Delete it

Modifikoje = Modify/Edit it

Link to comment
Share on other sites

Here's what I normally do:

It consists of two pages

 

 

Main Index Page:

<html>
<head>
<script type="text/javascript">
var form_id;
function confirm_delete(go_url)
{
var answer = confirm("Are you sure to delete this pick?");
if (answer)
{
location=go_url;
}
}
</script>
</head>

<body>

<?php
//open DB connection
include 'conndb.php'; 	
$sql = "select * from table;"; 
$result = mysql_query($sql,$conn);
while ($row = mysql_fetch_array($result)){
$id = $row['id'];

echo <<<END

<tr>
<td align="center"><a href="#" onClick="confirm_delete('delete.php?delete=true&id=$id');">Delete</a></td>
</tr>

END;
}
?>

</body>
</html>	

 

Delete Page:

<html>
<body>
<?php
include 'conndb.php';
$sql = "delete from table WHERE id = '$_GET[id]'";
$result = mysql_query($sql);

//print $sql;

if (!$result) {
echo "<div align ='center' class='error'>Error Updating";
echo "<br>";
echo "<br>";
echo "<a href='index.php'>Back to Admin Area</a></div>";
} else {
    echo "<div align ='center' class='header2'>Record Updated Successfully";
echo "<br>";
echo "<br>";
echo "<a href='index.php'>Back to Admin Area</a></div>";
}

?>
</body>
</html>

 

 

There is some javascript that will prompt you to ensure that you want to delete the row. The link will direct you to the delete page and then delete the record from the DB.  It will also tell you if it deleted successfully or not.  REMEMBER!!!!!  Once it's deleted...it's GONE!

 

Hope that helps!

Link to comment
Share on other sites

There is some javascript that will prompt you to ensure that you want to delete the row. The link will direct you to the delete page and then delete the record from the DB.  It will also tell you if it deleted successfully or not.  REMEMBER!!!!!  Once it's deleted...it's GONE!

 

Hope that helps!

 

Yep, it helped me very much and was easy to modify for my needs.  Thank you very very much ...

What i need not is a way to modify/update the db.

 

Thanks again ;)

Link to comment
Share on other sites

There is some javascript that will prompt you to ensure that you want to delete the row. The link will direct you to the delete page and then delete the record from the DB.  It will also tell you if it deleted successfully or not.  REMEMBER!!!!!  Once it's deleted...it's GONE!

 

Hope that helps!

 

Yep, it helped me very much and was easy to modify for my needs.  Thank you very very much ...

What i need NOW is a way to modify/update the db.

 

Thanks again ;)

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello again!

 

I have a little problem with the delete option. When i click on "Delete Link" of id 40 (for ex) it's not deleted the id 40 but the last id on the list. I don't know what the problem is... can you please help me?

 

Main page:

<?php
session_start();

if(!isset($_SESSION['loggedin'])) {
   header('Location: '.$domain.'index.php?error=1');
   exit();
}
?>
<html>
<head>
<script type="text/javascript">
var form_id;
function confirm_delete(go_url)
{
var answer = confirm("Jeni te sigurte per fshirjen e ketij evenimenti?");
if (answer)
{
location=go_url;
}
}
</script>
</head>

<body>
<?php
include '/includet/variabla.php';
include (BPATH_ADM . 'includet/dbconfig.php');
include (BPATH_ADM . 'includet/dblidhja.php');
$query="SELECT * FROM `ndeshje` ORDER BY `ndeshje`.`ID`";
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();
?>
<br /><br /><center><div class="ndeshjeshfaq">
<table width="598" border="0" align="center" class="ndeshjekoka">
  <tr>
    <td width="25" class="ndshfaqid">ID</td>
    <td width="35" class="ndshfaqsporti">Sporti</td>
    <td width="265" class="ndshfaqndeshja">Ndeshja</td>
    <td width="50" class="ndshfaqmenyra">Menyra</td>
    <td width="50" class="ndshfaqora">Ora</td>
    <td width="90" class="ndshfaqdata">Data</td>
    <td width="110" class="ndshfaqmod">X - Mod</td>
  </tr>
</table></center>


<?php
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"ID");
$ndeshja=mysql_result($result,$i,"ndeshja");
$ora=mysql_result($result,$i,"ora");
$data=mysql_result($result,$i,"data");
$menyra=mysql_result($result,$i,"menyra");
$sporti=mysql_result($result,$i,"sporti");
?>
<center>
<table width="598" border="0" class="ndeshjetabela">
  <tr>
    <td width="25" class="ndshfaqid"><?php echo $id; ?></td>
    <td width="35" class="ndshfaqsporti"><img src="..<?php echo $sporti; ?>" width="13"></td>
    <td width="265" class="ndshfaqndeshja"><?php echo $ndeshja;  ?></td>
    <td width="50" class="ndshfaqmenyra"><?php echo $menyra;  ?></td>
    <td width="50" class="ndshfaqora"><?php echo $ora;  ?></td>
    <td width="90" class="ndshfaqdata"><?php echo $data;  ?></td>
    <?php
include (BPATH_ADM . 'includet/dbconfig.php');
include (BPATH_ADM . 'includet/dblidhja.php');
$query="select * from ndeshje;";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){
$id = $row['ID'];

}
?>
    <td width="110" class="ndshfaqmod"><a href="#" onClick="confirm_delete('modulet/ndeshje/fshij.php?fshij=true&id=<?php echo $id;?>');">Fshije</a> - <a href="link-for-edit-entry.php">Mod</a></td>
  </tr>
</table></center>

</div>
<?php
$i++;
}
?>
</body>
</html>

 

Delete page:

<html>
<body>
<?php
include '/includet/variabla.php';
include (BPATH_ADM . 'includet/dbconfig.php');
include (BPATH_ADM . 'includet/dblidhja.php');
$sql = "delete from ndeshje WHERE ID = '$_GET[id]'";
$result = mysql_query($sql);

//print $sql;

if (!$result) {
   echo "<div align ='center' class='error'>Fshirja e ndeshjes deshtoi!";
   echo "<br>";
   echo "<br>";
   echo '<form><input type="button" class="buton" value="Kthehu Mbrapa" 
ONCLICK="history.go(-1)"></form>';
   } else {
    echo "<div align ='center' class='header2'>Ndeshja u fshi me sukses!";
   echo "<br>";
   echo "<br>";
   echo '<form><input type="button" class="buton" value="Kthehu Mbrapa" 
ONCLICK="history.go(-1)"></form>';
}
?>
</body>
</html>

 

Thank you in advance!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.