Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> System logowania w PHP i mssql
real24
post 1.11.2016, 19:27:34
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.11.2016

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


Chciałbym prosić o pomoc w znalezieniu tych błędów:
Warning: sqlsrv_query() expects parameter 1 to be resource, integer given
Warning: sqlsrv_has_rows() expects parameter 1 to be resource, boolean given

Z góry dziękuję za pomoc.


  1.  
  2. <?php
  3. $serverName = "(local)";
  4. $connectionInfo = array("Database"=>"mydatabase","UID"=>"myusername", "PWD"=>"mypassword");
  5. $conn = sqlsrv_connect( $serverName, $connectionInfo);
  6. if( $conn === false){
  7. echo "Error in connection.\n";
  8. die( print_r( sqlsrv_errors(), true));
  9. }else{
  10. $user = $_POST['user];
  11. $password = $_POST['password'];
  12.  
  13. $query = "SELECT * FROM [DATABASE_NAME].[dbo].[users] WHERE user='{$user}' AND"
  14. ."password='{$password}' AND active='1'";
  15. $result = sqlsrv_query($conn, $query);
  16.  
  17. if($result === false){
  18. die( print_r( sqlsrv_errors(), true));
  19. }
  20.  
  21. if(sqlsrv_has_rows($result) != 1){
  22. echo "User/password not found";
  23. }else{
  24.  
  25. while($row = sqlsrv_fetch_array($result)){
  26. $_SESSION['id'] = $row['id'];
  27. $_SESSION['name'] = $row['name'];
  28. $_SESSION['user'] = $row['user'];
  29.  
  30. }
  31.  
  32. header("Location: restrict.php");
  33. }
  34. }
  35.  
  36. ?>
  37.  





Go to the top of the page
+Quote Post
Pyton_000
post 1.11.2016, 21:36:08
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Zamień
  1. if( $conn === false){

na
  1. if( !$conn ){

i zobacz czy pomogło

PS. i tutaj Ci ciapka brakuje:
Kod
$user = $_POST['user];


Ten post edytował Pyton_000 1.11.2016, 21:36:30
Go to the top of the page
+Quote Post
real24
post 1.11.2016, 23:13:08
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.11.2016

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


Teraz mam coś takiego. Utworzyłem źródło danych ODBC dla mojej bazy danych, ale nic to nie dało.

Array ( [0] => Array ( [0] => 42S02 [SQLSTATE] => 42S02 [1] => 208 [code] => 208 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid object name '####'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid object name '####'. ) )
Go to the top of the page
+Quote Post
Pyton_000
post 2.11.2016, 07:20:02
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


"Invalid object name '####'. " - niepoprawna nazwa czegoś....
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: 13.06.2025 - 11:29