...

View Full Version : Edit Row ... Delete Row?



kleidi
02-21-2010, 04:09 PM
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

CallumJohnson
02-21-2010, 06:16 PM
This would require knowledge of MySQL and .php

For this i normally use something like:

but to get the right id in the url you'll have to echo the value from the database.


http://domain.tld/admin/users.php?id=1&status=delete



then add something like:



$id = $_GET['id'];
$status = $_GET['status'];


if($status == "delete") {/* Insert your code here for deletion*/ -->}

Not sure if this is the best way but its the way i've come to adopt
i imagine there are many ways of doing the same thing.

kleidi
02-21-2010, 08:24 PM
Thank you CallumJohnson ! I'm a newbie in php and i don't know how to do that. What i have just now is:


<?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/variabla.php';
include (BPATH_ADM . 'includet/dbconfig.php');
include (BPATH_ADM . 'includet/dblidhja.php');
$query="SELECT * FROM `ndeshje` ORDER BY `ndeshje`.`ora`";
$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="315" class="ndshfaqndeshja">Emri</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");
?>
<center>
<table width="598" border="0">
<tr>
<td width="55" class="ndshfaqid"><?php echo $id; ?></td>
<td width="315" class="ndshfaqndeshja"><?php echo $ndeshja; ?></td>
<td width="50" class="ndshfaqora"><?php echo $ora; ?></td>
<td width="90" class="ndshfaqdata"><?php echo $data; ?></td>
<td width="110" class="ndshfaqmod"><a href="link-for-delete-entry.php">X</a> - <a href="link-for-edit-entry.php">Mod</a></td>
</tr>
</table></center>

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

... the code for show all the db entry.
<a href="link-for-delete-entry.php">X</a> ::::: Here should put the delete link option.
<a href="link-for-edit-entry.php">Mod</a> ::::: Here should put the edit link option.

Any practically help, pleaseeeeeee?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum