Drukowana wersja tematu

Kliknij tu, aby zobaczyć temat w orginalnym formacie

Forum PHP.pl _ Przedszkole _ [PHP]Nie dodaje mi uzytkonika

Napisany przez: pawel06281990 8.07.2019, 00:37:48

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 (http://www.php.net/isset($_POST['newuser'])) {
  2. $username = $_POST['username'];
  3. $password = http://www.php.net/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 = http://www.php.net/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 (http://www.php.net/empty($_SESSION["username"])) {
  13. $userusername = "WHMCS";
  14. } else {
  15. $userusername = $_SESSION["username"];
  16. }
  17. addevent($userusername, " added " . $username . " as a registered user");
  18. http://www.php.net/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. http://www.php.net/var_dump($insert1);



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




Szukam problemu ale ja nic nie widzie.

Co może być nie tak??

Napisany przez: viking 8.07.2019, 05:18:39

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

Napisany przez: pawel06281990 8.07.2019, 13:21:02

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 = http://www.php.net/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 (http://www.php.net/empty($_SESSION["username"])) {
  13. $userusername = "WHMCS";
  14. } else {
  15. $userusername = $_SESSION["username"];
  16. }
  17.  
  18. addevent($userusername, " added " . $username . " as a registered user");
  19. http://www.php.net/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 (http://www.php.net/isset($_POST['newuser'])) {
  2.  
  3. $username = $_POST['username'];
  4.  
  5. $password = http://www.php.net/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. <http://december.com/html/4/element/form.html method="post" action="">
  2.  
  3. <http://december.com/html/4/element/div.html class="box-body">
  4.  
  5. <http://december.com/html/4/element/div.html class="form-group">
  6.  
  7. <http://december.com/html/4/element/label.html for="">Username</http://december.com/html/4/element/label.html>
  8.  
  9. <http://december.com/html/4/element/input.html type="text" class="form-control" id="" name="username" placeholder="Username">
  10.  
  11. </http://december.com/html/4/element/div.html>
  12.  
  13. <http://december.com/html/4/element/div.html class="form-group">
  14.  
  15. <http://december.com/html/4/element/label.html for="">Password</http://december.com/html/4/element/label.html>
  16.  
  17. <http://december.com/html/4/element/input.html type="password" class="form-control" name="password" id="" placeholder="Password">
  18.  
  19. </http://december.com/html/4/element/div.html>
  20.  
  21. <http://december.com/html/4/element/div.html class="form-group">
  22.  
  23. <http://december.com/html/4/element/label.html for="">First Name</http://december.com/html/4/element/label.html>
  24.  
  25. <http://december.com/html/4/element/input.html type="text" class="form-control" name="fname" id="" placeholder="First Name">
  26.  
  27. </http://december.com/html/4/element/div.html>
  28.  
  29. <http://december.com/html/4/element/div.html class="form-group">
  30.  
  31. <http://december.com/html/4/element/label.html for="">Last Name</http://december.com/html/4/element/label.html>
  32.  
  33. <http://december.com/html/4/element/input.html type="text" class="form-control" name="lname" id="" placeholder="Last Name">
  34.  
  35. </http://december.com/html/4/element/div.html>
  36.  
  37. <http://december.com/html/4/element/div.html class="form-group">
  38.  
  39. <http://december.com/html/4/element/label.html for="">Email</http://december.com/html/4/element/label.html>
  40.  
  41. <http://december.com/html/4/element/input.html type="email" class="form-control" name="email" id="" placeholder="Email">
  42.  
  43. </http://december.com/html/4/element/div.html>
  44.  
  45. <http://december.com/html/4/element/div.html class="form-group">
  46.  
  47. <http://december.com/html/4/element/label.html>Access Level</http://december.com/html/4/element/label.html>
  48.  
  49. <http://december.com/html/4/element/select.html class="form-control" name="access">
  50.  
  51. <http://december.com/html/4/element/option.html value="5">Administrator</http://december.com/html/4/element/option.html>
  52.  
  53. <http://december.com/html/4/element/option.html value="4">Technician</http://december.com/html/4/element/option.html>
  54.  
  55. <http://december.com/html/4/element/option.html value="3">Helper</http://december.com/html/4/element/option.html>
  56.  
  57. <http://december.com/html/4/element/option.html value="2">Read Only</http://december.com/html/4/element/option.html>
  58.  
  59. <http://december.com/html/4/element/option.html value="1">User</http://december.com/html/4/element/option.html>
  60.  
  61. <http://december.com/html/4/element/option.html value="0">Disabled</http://december.com/html/4/element/option.html>
  62.  
  63. </http://december.com/html/4/element/select.html>
  64.  
  65. </http://december.com/html/4/element/div.html>
  66.  
  67. </http://december.com/html/4/element/div.html><!-- /.box-body -->
  68.  
  69. <http://december.com/html/4/element/div.html class="box-footer">
  70.  
  71. <http://december.com/html/4/element/input.html type="hidden" name="newuser" value="yes">
  72.  
  73. <http://december.com/html/4/element/button.html type="submit" name="go" class="btn btn-primary">Add user</http://december.com/html/4/element/button.html>
  74.  
  75. </http://december.com/html/4/element/div.html>
  76.  
  77. </http://december.com/html/4/element/form.html>


Co jest nie tak że nie zapisuje wogule.


Napisany przez: viking 8.07.2019, 13:26:32

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.

Napisany przez: pawel06281990 8.07.2019, 13:42:45

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
https://github.com/gaza1994/SHOUTcast-Manager Do zarządzania serwerami SHOUTcast.

Ale coś nie działa tak jak miał działać

Napisany przez: nospor 8.07.2019, 13:47:52

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?

Napisany przez: viking 8.07.2019, 13:48:00

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

Napisany przez: pawel06281990 8.07.2019, 14:15:09

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


Dzięki Viking za pomoc.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)