Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Nie dodaje mi uzytkonika
pawel06281990
post 8.07.2019, 00:37:48
Post #1





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Witam mam Problem z dodawaniem użytkownika, nie wiem dla czego nie dodaje mi go do bazy


Tak wygląda mój skrypt

Dane przekazywane do zapisu
  1. if (isset($_POST['newuser'])) {
  2. $username = $_POST['username'];
  3. $password = md5($_POST['password']);
  4. $email = $_POST['email'];
  5. $fname = $_POST['fname'];
  6. $lname = $_POST['lname'];
  7. $access = $_POST['access'];
  8. adduser($username, $password, $fname, $lname, $email, $access);
  9.  
  10. }


A tu jest zapis we funkcji
  1. function adduser($username, $password, $fname, $lname, $email, $access) {
  2. $db = dbconnect();
  3. $insert1 = array(
  4. "username" => $username,
  5. "password" => $password,
  6. "fname" => $fname,
  7. "lname" => $lname,
  8. "email" => $email,
  9. "access" => $level
  10. );
  11. $db->insert("members", $insert1);
  12. if (empty($_SESSION["username"])) {
  13. $userusername = "WHMCS";
  14. } else {
  15. $userusername = $_SESSION["username"];
  16. }
  17. addevent($userusername, " added " . $username . " as a registered user");
  18. echo "<div class=\"alert alert-success alert-dismissable\"><i class=\"fa fa-check\"></i><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button><b>Success!</b> Added " . $username . " successfully!</div>";
  19.  
  20. }


Kiedy sprawdzam czy dane docierają to mi pokazuje że dane docierają
A sprawdzam to tym

  1. var_dump($insert1);



Tu jest formularz dodawania użytkownika
  1. <form method="post" action="">
  2. <div class="box-body">
  3. <div class="form-group">
  4. <label for="">Username</label>
  5. <input type="text" class="form-control" id="" name="username" placeholder="Username">
  6. </div>
  7. <div class="form-group">
  8. <label for="">Password</label>
  9. <input type="password" class="form-control" name="password" id="" placeholder="Password">
  10. </div>
  11. <div class="form-group">
  12. <label for="">First Name</label>
  13. <input type="text" class="form-control" name="fname" id="" placeholder="First Name">
  14. </div>
  15. <div class="form-group">
  16. <label for="">Last Name</label>
  17. <input type="text" class="form-control" name="lname" id="" placeholder="Last Name">
  18. </div>
  19. <div class="form-group">
  20. <label for="">Email</label>
  21. <input type="email" class="form-control" name="email" id="" placeholder="Email">
  22. </div>
  23. <div class="form-group">
  24. <label>Access Level</label>
  25. <select class="form-control" name="access">
  26. <option value="5">Administrator</option>
  27. <option value="4">Technician</option>
  28. <option value="3">Helper</option>
  29. <option value="2">Read Only</option>
  30. <option value="1">User</option>
  31. <option value="0">Disabled</option>
  32. </select>
  33. </div>
  34. </div><!-- /.box-body -->
  35. <div class="box-footer">
  36. <input type="hidden" name="newuser" value="yes">
  37. <button type="submit" name="go" class="btn btn-primary">Add user</button>
  38. </div>
  39. </form>




Szukam problemu ale ja nic nie widzie.

Co może być nie tak??

Ten post edytował pawel06281990 8.07.2019, 00:39:07
Go to the top of the page
+Quote Post
viking
post 8.07.2019, 05:18:39
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


W funkcji "access" => $level nie masz takiej zmiennej.


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 8.07.2019, 13:21:02
Post #3





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Zmieniłem parametry ale nadal nie zapisuje

tak wygląda funkcja która powinna zapisywać

  1. function adduser($username, $password, $fname, $lname, $email, $level) {
  2. $db = dbconnect();
  3. $insert = array(
  4. "username" => $username,
  5. "password" => $password,
  6. "fname" => $fname,
  7. "lname" => $lname,
  8. "email" => $email,
  9. "access" => $level
  10. );
  11. $db->insert("members", $insert);
  12. if (empty($_SESSION["username"])) {
  13. $userusername = "WHMCS";
  14. } else {
  15. $userusername = $_SESSION["username"];
  16. }
  17.  
  18. addevent($userusername, " added " . $username . " as a registered user");
  19. echo "<div class=\"alert alert-success alert-dismissable\"><i class=\"fa fa-check\"></i><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button><b>Success!</b> Added " . $username . " successfully!</div>";
  20. }


A tu jest skrypt który ma pobierać z formularza

  1. if (isset($_POST['newuser'])) {
  2.  
  3. $username = $_POST['username'];
  4.  
  5. $password = md5($_POST['password']);
  6.  
  7. $email = $_POST['email'];
  8.  
  9. $fname = $_POST['fname'];
  10.  
  11. $lname = $_POST['lname'];
  12.  
  13. $access = $_POST['access'];
  14.  
  15. adduser($username, $password, $fname, $lname, $email, $access);
  16.  
  17. }


A tu formularz

  1. <form method="post" action="">
  2.  
  3. <div class="box-body">
  4.  
  5. <div class="form-group">
  6.  
  7. <label for="">Username</label>
  8.  
  9. <input type="text" class="form-control" id="" name="username" placeholder="Username">
  10.  
  11. </div>
  12.  
  13. <div class="form-group">
  14.  
  15. <label for="">Password</label>
  16.  
  17. <input type="password" class="form-control" name="password" id="" placeholder="Password">
  18.  
  19. </div>
  20.  
  21. <div class="form-group">
  22.  
  23. <label for="">First Name</label>
  24.  
  25. <input type="text" class="form-control" name="fname" id="" placeholder="First Name">
  26.  
  27. </div>
  28.  
  29. <div class="form-group">
  30.  
  31. <label for="">Last Name</label>
  32.  
  33. <input type="text" class="form-control" name="lname" id="" placeholder="Last Name">
  34.  
  35. </div>
  36.  
  37. <div class="form-group">
  38.  
  39. <label for="">Email</label>
  40.  
  41. <input type="email" class="form-control" name="email" id="" placeholder="Email">
  42.  
  43. </div>
  44.  
  45. <div class="form-group">
  46.  
  47. <label>Access Level</label>
  48.  
  49. <select class="form-control" name="access">
  50.  
  51. <option value="5">Administrator</option>
  52.  
  53. <option value="4">Technician</option>
  54.  
  55. <option value="3">Helper</option>
  56.  
  57. <option value="2">Read Only</option>
  58.  
  59. <option value="1">User</option>
  60.  
  61. <option value="0">Disabled</option>
  62.  
  63. </select>
  64.  
  65. </div>
  66.  
  67. </div><!-- /.box-body -->
  68.  
  69. <div class="box-footer">
  70.  
  71. <input type="hidden" name="newuser" value="yes">
  72.  
  73. <button type="submit" name="go" class="btn btn-primary">Add user</button>
  74.  
  75. </div>
  76.  
  77. </form>


Co jest nie tak że nie zapisuje wogule.

Go to the top of the page
+Quote Post
viking
post 8.07.2019, 13:26:32
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Nie wiem co robi ani czym jest twoja funkcja zapisująca dane. Na jej poziomie wyświetl jakiś wyjątek/błąd zapytania albo sprawdź w logach.


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 8.07.2019, 13:42:45
Post #5





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


Właśnie o to chodzi że nie ma błędów zapisu niby operacja dodania się udaje a użytkownika w bazie nie ma dodanego bo korzystam
z tego skryptu Do zarządzania serwerami SHOUTcast.

Ale coś nie działa tak jak miał działać
Go to the top of the page
+Quote Post
nospor
post 8.07.2019, 13:47:52
Post #6





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Cytat
Właśnie o to chodzi że nie ma błędów zapisu niby operacja dodania się udaje

Tja....
$db->insert("members", $insert);
Nigdzie w tym kodzie nie widze bys raportowal/logowal jakikolwiek blad wiec moze dlatego zadnych bledow nie dostajesz?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
viking
post 8.07.2019, 13:48:00
Post #7





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Po insert zrób var_dump($db->getLastError());


--------------------
Go to the top of the page
+Quote Post
pawel06281990
post 8.07.2019, 14:15:09
Post #8





Grupa: Zarejestrowani
Postów: 281
Pomógł: 0
Dołączył: 10.01.2014

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


ok w bazie nie było wartości domyślnej dla jednej wartości którą mam w bazie


Dzięki Viking za pomoc.
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 20:39