Autor Beitrag
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Do 25.05.06 16:27 
Hey Leute,

ich bin gerade dabei, ein kleines Portal zu entwickeln. Für Login und so weiter benutze ich MySQL. Hat auch bis eben alles wunderbar funktioniert. Login und Registrieren ging einwandfrei. Jetzt hab ich eben ein bischen an den Zellenhintergrundfarben von der Tabelle gedreht und jetzt geht weder Login noch Registrieren.

Jetzt ich bekomme immer diese Meldung:
Firefox 1.5 hat folgendes geschrieben:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/htdocs/dannys/freundeonline/script/usr_actions.php on line 6


In besagter Datei steht folgendes:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
<?
function valid_usr($usrname,$usrpw)
{
 // Testen ob Username und Passwort stimmen
 $select  = mysql_query('SELECT * FROM userdata');
 $count   = mysql_num_rows($select);

 for($i=0;$i<$count;$i++)
 {
  $line   = mysql_fetch_assoc($select);
  if (($line['name'] == $usrname) && ($line['pw'] == $usrpw))
   return true;  
 } 
 return false;
}
?>

Laut selfphp ist das alles syntaktisch korrekt. Also auch Zeile 6.

Wisst ihr woran es liegen kann, dass ich trotzdem neuerdings die obenstehende Fehlermeldung bekomme? Muss ich vielleicht die Zugriffsrechte der Datei auf dem Server ändern?

Gruss
Daniel

Moderiert von user profile iconTino: Überflüssige Zeilenumbrüche entfernt.
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Do 25.05.06 16:53 
Hallo Danny87 :wave:
den Fehler hatte ich auch letztens. Das liegt an der in PHP nicht vorhandenen Typsicherheit. Ich Delphi-verwöhnter Hobby-Progger hab mich da auch ne ganz Weile abgesucht, bis ich dahinter gekommen bin:
In diesem Fall is $select nämlich wahrscheinlich gar kein MySQLResult(siehe Warnung), sondern false. Ergo: SELECT hat nicht geklappt/hat keine Ergebnisse zurückgeliefert, weil in userdata nix drin is. ==> einfach vorher auf !== false prüfen...

mfg

Christian

_________________
Kaum macht man's richtig, schon klappts!
Danny87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Fr 26.05.06 00:56 
Hmm...okay, das geht.
Aber wie krieg ich jetzt hin, dass er wieder korrekt selektiert?
Denn es ist GANZ BESTIMMT ein Datensatz vorhanden (4 Stück um genau zu sein)

Gruss
Daniel
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Fr 26.05.06 04:38 
Wäre es nich angebrachter, das Query mit einer Verbindungskennung aufzurufen?

Ansonsten siehts so aus, wie's bereits gepostet wurde: SELECT hat nicht geklappt - das Ergebnis von Query prüfen und fertig.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
Phobeus
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1280

Linux (FC6), WinXP Pro (Box)
D6 Pers, D7 Pro, FPC 2.x
BeitragVerfasst: Fr 26.05.06 08:07 
Erstmal gewöhne Dir am besten gleich die *-Abfragen ab und gebe nur das an, was Du wirklich brauchst. Die Abfrage ist ungültig und MySQL wird einen Grund haben. Prüfe daher exakt nach, ob das ganze wirklcih existiert. Jage die Abfrage ggf. zuvor durch ein zweites System (phpmyadmin). Sollte das dort klappen, will ich wetten, dass Du auch nicht prüfst, ob das Login zur Datenbank überhaupt erfolgreich war und die richtige Datenbank selektiert werden konnte.

_________________
"Menschen sterben nicht wenn man sie zu Grabe trägt, sondern wenn sie ihre Träume verlieren..."
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Sa 27.05.06 16:38 
Das ist performancemäßiger Wahnsinn!!! Stell dir vor du hast 10.000 user.... Mach lieber ein select auf username und passwort. wenn du keine Rückgabe bekommst weißt du, dass der user falsche Daten eingegeben hat.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
Danny87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Sa 27.05.06 21:28 
Jetzt hab ichs so:

ausblenden Quelltext
1:
2:
3:
4:
$select  = mysql_query('SELECT name AND pw FROM userdata where name = \''.$usrname.'\' AND pw = \''.$usrpw.'\'');
 if ($select)
  echo('Eingeloggt');
 else echo('Fehler');


Allerdings funktioniert das genausowenig :nixweiss:
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 27.05.06 21:39 
ausblenden Quelltext
1:
2:
echo "$usrname";
echo $usrpw;

Kannst ja erstmal prüfen, ob die Variablen korrekt belegt sind ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: So 28.05.06 08:14 
user profile iconDanny87 hat folgendes geschrieben:
Jetzt hab ichs so:

ausblenden Quelltext
1:
2:
3:
4:
$select  = mysql_query('SELECT name AND pw FROM userdata where name = \''.$usrname.'\' AND pw = \''.$usrpw.'\'');
 if ($select)
  echo('Eingeloggt');
 else echo('Fehler');


Allerdings funktioniert das genausowenig :nixweiss:


:autsch: Von escaping hast du noch nie was gehört oder? Schau dir mal mysql_real_escape_string an.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
Danny87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: So 28.05.06 11:58 
user profile iconblackbirdXXX hat folgendes geschrieben:

:autsch: Von escaping hast du noch nie was gehört oder? Schau dir mal mysql_real_escape_string an.

Nee hab ich nicht. Ich beschäftige mich erst seit ein paar Tagen mit MySQL ;-)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 12:10 
Hast du schon überprüft, ob die Variablen überhaupt richtig übertragen wurden?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
adfontes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 82

Win7 (64bit), WinXP
Delphi 2010 Prof, Delphi XE2 (Trial)
BeitragVerfasst: So 28.05.06 18:04 
user profile iconDanny87 hat folgendes geschrieben:
Jetzt hab ichs so:

ausblenden Quelltext
1:
2:
3:
4:
$select  = mysql_query('SELECT name AND pw FROM userdata where name = \''.$usrname.'\' AND pw = \''.$usrpw.'\'');
 if ($select)
  echo('Eingeloggt');
 else echo('Fehler');


Allerdings funktioniert das genausowenig :nixweiss:


ich würds glaub ich so versuchen (einfach mal so spontan):

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
<?php
function valid_usr($username,$usrpw) {
  $loginqry = "SELECT `name` 
    FROM `userdata` 
    WHERE `name` = '".$username."'
    AND `pw` = '".$usrpw."'
    LIMIT 1";
  $loginrlt = mysql_query($loginqry);

  if ($loginrlt) {
    return "true";
    die();
  }
  return "false";
}
?>


einfach ma so als test, kA obs wirklich funzt


greetz
adfontes
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: So 28.05.06 19:32 
user profile iconadfontes hat folgendes geschrieben:
ich würds glaub ich so versuchen (einfach mal so spontan):

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
<?php
function valid_usr($username,$usrpw) {
  $loginqry = "SELECT `name` 
    FROM `userdata` 
    WHERE `name` = '".$username."'
    AND `pw` = '".$usrpw."'
    LIMIT 1";
  $loginrlt = mysql_query($loginqry);

  if ($loginrlt) {
    return "true";
    die();
  }
  return "false";
}
?>


einfach ma so als test, kA obs wirklich funzt


Und wo ist das gottverdammte escaping? Hört mir denn keiner zu???

_________________
Klein, schwarz und ärgert Techniker? Jumper!
adfontes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 82

Win7 (64bit), WinXP
Delphi 2010 Prof, Delphi XE2 (Trial)
BeitragVerfasst: So 28.05.06 20:33 
user profile iconblackbirdXXX hat folgendes geschrieben:

Und wo ist das gottverdammte escaping? Hört mir denn keiner zu???


ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
...blabla ...

// regex
$search = "/(?<!\\\)\'/";
$search2 = "/(?<!\\\)\\"/";
// replace with
$replace = "\\'";
$replace2 = "\\\"";

// escape $username
preg_replace ($search, $replace, $username);
preg_replace ($search2, $replace2, $username);
// escape $usrpw
preg_replace ($search, $replace, $usrpw);
preg_replace ($search2, $replace2, $usrpw);

...blabla...


besser?

(sollte hoffe ich mal funktionieren, bin nich so der regex freak...)

greetz
adfontes
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: So 28.05.06 21:03 
user profile iconadfontes hat folgendes geschrieben:
user profile iconblackbirdXXX hat folgendes geschrieben:

Und wo ist das gottverdammte escaping? Hört mir denn keiner zu???


ausblenden Quelltext
1:
...blabla ...					


besser?

Nein. Entweder man nutzt das PEAR module, was wirklich escapen kann oder mysql_real_escape_string. Weil im Gegensatz zu deiner Lösung funktioniert letzteres wirklich.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
adfontes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 82

Win7 (64bit), WinXP
Delphi 2010 Prof, Delphi XE2 (Trial)
BeitragVerfasst: So 28.05.06 21:08 
user profile iconblackbirdXXX hat folgendes geschrieben:
user profile iconadfontes hat folgendes geschrieben:
user profile iconblackbirdXXX hat folgendes geschrieben:

Und wo ist das gottverdammte escaping? Hört mir denn keiner zu???


ausblenden Quelltext
1:
...blabla ...					


besser?

Nein. Entweder man nutzt das PEAR module, was wirklich escapen kann oder mysql_real_escape_string. Weil im Gegensatz zu deiner Lösung funktioniert letzteres wirklich.


Wie wärs, wenn du mal was produktives postest, anstatt nur rumzunörgeln? :schmoll: :motz:
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: So 28.05.06 21:35 
user profile iconadfontes hat folgendes geschrieben:
Wie wärs, wenn du mal was produktives postest, anstatt nur rumzunörgeln? :schmoll: :motz:


Ich hab bereits das dritte mal geschrieben, dass mysql_real_escape_string die Lösung wäre. Auf at.php.net oder einem anderen Mirror hätte man ein Beispiel gefunden. Und hier hab ich bereits eines geschrieben: www.delphi-forum.de/....php?p=358046#358046

_________________
Klein, schwarz und ärgert Techniker? Jumper!