ziedinjsh Posted October 18, 2009 Report Share Posted October 18, 2009 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ēš? Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 ?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"; ?> Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 18, 2009 Report Share Posted October 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 18, 2009 Author Report Share Posted October 18, 2009 (edited) 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 October 18, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 varbūt tāpēc ka viņš tev ir ciklā iemaukts? izņem ārpus cikla Quote Link to comment Share on other sites More sharing options...
marcis Posted October 18, 2009 Report Share Posted October 18, 2009 Tu vispirms iegūsti lietotāju sarakstu un tikai pēc tam iedzēs. Nešķiet, ka vajadzētu darīt otrādi? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.