Jump to content
php.lv forumi

delete user


ziedinjsh

Recommended Posts

nesaprotu kapēc rāda šadu notici:

Notice: Undefined index: users in /home/produc/public_html/mp3/1/admin/users.php on line 12

 

Notice: Use of undefined constant delete - assumed 'delete' in /home/produc/public_html/mp3/1/admin/users.php on line 12

 

users.php:

<?php
include "misc/config.php";
include "header.php";
include "left.php";

$result = mysql_query("SELECT * FROM users ORDER BY id DESC");
while($data = mysql_fetch_array($result))
 {



if($_GET["users"]==delete)
{
   $sql = "DELETE FROM users WHERE id=$id";
   $result = mysql_query($sql);
   echo "User deleted!";
}


echo "<form method='post' action='index.php?page=users'>";
echo "<table><tr>";
echo "<td>username</td><td>".$data['username']."</td>";
echo "</tr><tr>";
echo "<td>email</td><td>".$data['email']."</td>";
echo "</tr></table>";
echo "".$data['id']."";
echo "<a href='users.php?page=delete&id=".$data['id']."'>delete user</a>";
echo "</form>";
echo "<hr>";
}



include "footer.php";
?>

 

kapēc rodas šāda notice un kapēc nedzēš?

Link to comment
Share on other sites

?users=delete

hmm izdari lūk šādi

 

if($_GET["page"]== "delete")
{
$id = $_GET['id'];
   $sql = "DELETE FROM users WHERE id=".$id."";
   $result = mysql_query($sql);
   echo "User deleted!";
}


echo "<form method='post' action='index.php?page=users'>";
echo "<table><tr>";
echo "<td>username</td><td>".$data['username']."</td>";
echo "</tr><tr>";
echo "<td>email</td><td>".$data['email']."</td>";
echo "</tr></table>";
echo "".$data['id']."";
echo "<a href='?page=delete&id=".$data['id']."'>delete user</a>";
echo "</form>";
echo "<hr>";
}



include "footer.php";
?>

Link to comment
Share on other sites

Kļūda ir te:

if($_GET["users"]==delete)

 

nav definēts tāds delete - varbūt tu domāji "delete" (kā stringu)?

 

Un vispār tev tur ir kaut kas jocīgs un nesaprotu kā tas īsti darbojās un tur viss izskatās līki. Kur ir definēts $id? Un kādēļ viņš iet cauri visiem lietotājiem? Nesaprotu...padomā vai tur ir tiešām tas ko vēlies.

Link to comment
Share on other sites

nu ok.. tagadir šādi

<?php
include "misc/config.php";
include "header.php";
include "left.php";



$result = mysql_query("SELECT * FROM users ORDER BY id DESC");
while($data = mysql_fetch_array($result))
{

if(isset ($_GET['id']))
{
$id = $_GET['id'];

$query= mysql_query("delete FROM users where id =$id")or die(mysql_error());
}




echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<table><tr>";
echo "<td>username</td><td>".$data['username']."</td>";
echo "</tr><tr>";
echo "<td>email</td><td>".$data['email']."</td>";
echo "</tr></table>";
echo "".$data['id']."";
echo "<a href='users.php?page=delete&id=".$data['id']."'>delete user</a>";
echo "</form>";
echo "<hr>";

}


include "footer.php";
?>

 

kods strādā, bet tikai ja spiez uz linka 2x.. vienreiz nospiež nekas nenotiek.. pārlādējas tikai lapa, bet kad nospiež otro reizi tad izdzēš.. kapēc tā?

Edited by ziedinjsh
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...