Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/mysql] edytowanie rekordow
dirtyhustlaz
post
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 29.03.2012

Ostrzeżenie: (0%)
-----


skrypt pobiera mi dane z bazy i pokazuje je w formularzu, ale jak chce je zminie i chce zaktualizowac to wywala mi blad:
  1. Notice: Undefined index: id in F:\EasyPHP-12.1\www\glencaldy\editstudent.php on line 33


w tabeli 'student' mam pola: studentid, firstname, surname, username, password. chce zeby moliwa byla edycja wsyzstkich poza studentid.
jak zmienialem w tej 33 lini id na student id to wogole nie pobiera danych i nie wyskakuje ten blad juz na glownej stronie. oto kod mojego skryptu edycji danych. moglby ktos mi pomoc z tym albo dac jakies wskazowki? musze to skonczyc do szkoly w tym tygodniiu


  1. <?php
  2.  
  3. // Connects to your Database
  4.  
  5. mysql_connect("localhost", "root", "") or die(mysql_error());
  6.  
  7. mysql_select_db("glencaldy") or die(mysql_error());
  8.  
  9.  
  10. //checks cookies to make sure they are logged in
  11.  
  12. if (isset($_COOKIE['ID_my_site'])) {
  13. $username = $_COOKIE['ID_my_site'];
  14.  
  15. $pass = $_COOKIE['Key_my_site'];
  16.  
  17. $check = mysql_query("SELECT * FROM student WHERE username = '$username'") or die(mysql_error());
  18.  
  19. while ($info = mysql_fetch_array($check)) {
  20. //if the cookie has the wrong password, they are taken to the login page
  21.  
  22. if ($pass != $info['password']) {
  23. header("Location: login.php");
  24.  
  25. }
  26.  
  27.  
  28.  
  29. //otherwise they are shown the admin area
  30.  
  31. else {
  32. $a = trim($_REQUEST['a']);
  33. $id = trim($_GET['id']);
  34. if ($a == 'edit' and !empty($id)) {
  35. $result = mysql_query("SELECT * FROM student WHERE
  36. studentid='$id'") or die('Error');
  37.  
  38. if (mysql_num_rows($result) > 0) {
  39. // read content of table
  40. $r = mysql_fetch_assoc($result);
  41. echo "<h1>EDIT STUDENT</h1><p>";
  42. echo '<form action="editstudent.php" method="post">
  43. <input type="hidden" name="a" value="save" />
  44. <input type="hidden" name="studentid" value="' . $id . '" />
  45. First name:<br />
  46. <input type="text" name="firstname"
  47. value="' . $r['firstname'] . '" /><br />
  48. Surname:<br />
  49. <input type="text" name="surname"
  50. value="' . $r['surname'] . '" /><br />
  51. Username:<br />
  52. <input type="text" name="username"
  53. value="' . $r['username'] . '" /><br />
  54. Password:<br />
  55. <input type="text" name="password"
  56. value="' . $r['password'] . '" /><br />
  57. <input type="submit" value="Update Record" />
  58. </form>';
  59. echo "<a href=deletestudent.php><< Back to delete/edit menu</a><p>";
  60. echo "<a href=menu.php><< Back to main menu</a><p>";
  61.  
  62. }
  63.  
  64. }
  65. }
  66.  
  67. }
  68. } elseif ($a == 'save') {
  69. // get the new records from form
  70. $id = $_POST['studentid'];
  71. $firstname = trim($_POST['firstname']);
  72. $surname = trim($_POST['surname']);
  73. $username = trim($_POST['username']);
  74. $password = trim($_POST['password']);
  75. // update table
  76. mysql_query("UPDATE studnet SET firstname='$firstname',
  77. surname='$surname', username='&username', password='$password' WHERE studentid='$id'") or die('Error');
  78. echo 'records updated';
  79. }
  80.  
  81. else
  82. //if the cookie does not exist, they are taken to the login screen
  83. {
  84. header("Location: login.php");
  85.  
  86. }
  87.  
  88. ?>


tutaj wrzucam paczke z calym skryptem: https://dl.dropbox.com/u/63492647/glencaldy_dp.zip
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




Rety.... zadałem proste pytania:
Cytat
Przesyłasz to ID? Przesyłasz GETem czy POSTem?
Odpowiedz na nie bo to one są kluczem do rozwiązanie tej niesamowitej zagadki....
Skoro nie ma ID to niewyświetlanie błędu ci nie rozwiąze problemu, skoro ty polegasz na danych z tego ID....
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 29.12.2025 - 00:37