s2ext
Off Topic => Talk => Thema gestartet von: Robo01 am September 08, 2008, 20:12:59 Nachmittag
-
Mein PHP-Programm nimmt nur den ersten User aus der MySQL-Tabelle wahr:
- <?php</span></li><li style="" class="li2">[url=http://www.php.net/define]<span style="color: #000066;">define</span>[/url] <span style="color: #66cc66;">(</span> <span style="color: #ff0000;">'MYSQL_BENUTZER'</span>, <span style="color: #ff0000;">'root'</span> <span style="color: #66cc66;">)</span>;</li><li style="" class="li2">[url=http://www.php.net/define]<span style="color: #000066;">define</span>[/url] <span style="color: #66cc66;">(</span> <span style="color: #ff0000;">'MYSQL_DATENBANK'</span>, <span style="color: #ff0000;">'mysqlpasswort'</span> <span style="color: #66cc66;">)</span>;</li><li style="" class="li2"> </li><li style="" class="li1"><span style="color: #0000ff;">$db_link</span> = @[url=http://www.php.net/if]<span style="color: #b1b100;">if</span>[/url] <span style="color: #66cc66;">(</span> ! <span style="color: #0000ff;">$db_link</span> <span style="color: #66cc66;">)</span></li><li style="" class="li1"><span style="color: #66cc66;">{</span></li><li style="" class="li2"> <span style="color: #808080; font-style: italic;">// hier sollte dann später dem Programmierer eine</span></li><li style="" class="li1"> <span style="color: #808080; font-style: italic;">// E-Mail mit dem Problem zukommen gelassen werden</span></li><li style="" class="li2"> <span style="color: #808080; font-style: italic;">// die Fehlermeldung für den Programmierer sollte</span></li><li style="" class="li1"> <span style="color: #808080; font-style: italic;">// das Problem ausgeben mit: mysql_error()</span></li><li style="" class="li2"> die<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'keine Verbindung zur Zeit möglich - später probieren '</span><span style="color: #66cc66;">)</span>;</li><li style="" class="li1"><span style="color: #66cc66;">}</span></li><li style="" class="li2"> </li><li style="" class="li1"><span style="color: #0000ff;">$db_sel</span> = [url=http://www.php.net/mysql_query]<span style="color: #000066;">mysql_query</span>[/url]<span style="color: #66cc66;">(</span> <span style="color: #0000ff;">$sql</span> <span style="color: #66cc66;">)</span>;</li><li style="" class="li1">[url=http://www.php.net/mysql_error]<span style="color: #000066;">mysql_error</span>[/url]<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</li><li style="" class="li2"><span style="color: #66cc66;">}</span></li><li style="" class="li1"> </li><li style="" class="li2">[url=http://www.php.net/while]<span style="color: #b1b100;">while</span>[/url] <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$zeile</span> = [url=http://www.php.net/if]<span style="color: #b1b100;">if</span>[/url] <span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'username'</span><span style="color: #66cc66;">]</span><><span style="color: #ff0000;">''</span><span style="color: #66cc66;">)</span> and <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'passwort'</span><span style="color: #66cc66;">]</span><><span style="color: #ff0000;">''</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></li><li style="" class="li1"> </li><li style="" class="li2">[url=http://www.php.net/else]<span style="color: #b1b100;">else</span>[/url]<span style="color: #66cc66;">{</span></li><li style="" class="li1">[url=http://www.php.net/else]<span style="color: #b1b100;">else</span>[/url]<span style="color: #66cc66;">{</span></li><li style="" class="li2"> </li><li style="" class="li1">[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #0000ff;">$zeile</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'übermich'</span><span style="color: #66cc66;">]</span>;</li><li style="" class="li2">[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #0000ff;">$inhalt</span>;</li><li style="" class="li2">[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #ff0000;">'<a href="msql-logout.php">Logout</a>'</span>;</li><li style="" class="li2">exit;</li><li style="" class="li1"><span style="color: #66cc66;">}</span>[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #ff0000;">'</span></li><li style="" class="li2"><span style="color: #ff0000;"><form action="mysql-passwortg.php" method=get enctype="text/plain"></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"><input type="Text" name="username" value="" size="30" maxlength="50"></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"><br /></span></li><li style="" class="li1"><span style="color: #ff0000;"><br /></span></li><li style="" class="li2"><span style="color: #ff0000;"> </span></li><li style="" class="li1"><span style="color: #ff0000;"><input type="password" name="passwort" value="" size="30" maxlength="50"></span></li><li style="" class="li2"><span style="color: #ff0000;"> </span></li><li style="" class="li1"><span style="color: #ff0000;"><br /></span></li><li style="" class="li2"><span style="color: #ff0000;"><br /></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"><input type="Submit" name="login" value="Login"></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"></form>'</span>;</li><li style="" class="li1"> </li><li style="" class="li2">exit;</li><li style="" class="li1"><span style="color: #66cc66;">}</span></li><li style="" class="li2"><span style="color: #66cc66;">}</span></li><li style="" class="li1"> </li><li style="" class="li2"> </li><li style="" class="li1">[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #0000ff;">$zeile</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'übermich'</span><span style="color: #66cc66;">]</span>;</li><li style="" class="li1">[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #0000ff;">$inhalt</span>;</li><li style="" class="li1">[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #ff0000;">'<a href="msql-logout.php">Logout</a>'</span>;</li><li style="" class="li1">exit;</li><li style="" class="li2"><span style="color: #66cc66;">}</span>[url=http://www.php.net/echo]<span style="color: #b1b100;">echo</span>[/url] <span style="color: #ff0000;">'</span></li><li style="" class="li2"><span style="color: #ff0000;"><form action="mysql-passwortg.php" method=get enctype="text/plain"></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"><input type="Text" name="username" value="" size="30" maxlength="50"></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"><br /></span></li><li style="" class="li1"><span style="color: #ff0000;"><br /></span></li><li style="" class="li2"><span style="color: #ff0000;"> </span></li><li style="" class="li1"><span style="color: #ff0000;"><input type="password" name="passwort" value="" size="30" maxlength="50"></span></li><li style="" class="li2"><span style="color: #ff0000;"> </span></li><li style="" class="li1"><span style="color: #ff0000;"><br /></span></li><li style="" class="li2"><span style="color: #ff0000;"><br /></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"><input type="Submit" name="login" value="Login"></span></li><li style="" class="li1"><span style="color: #ff0000;"> </span></li><li style="" class="li2"><span style="color: #ff0000;"></form></span></li><li style="" class="li1"><span style="color: #ff0000;">'</span>;</li><li style="" class="li2">exit;</li><li style="" class="li1"><span style="color: #66cc66;">}</span></li><li style="" class="li2"><span style="color: #66cc66;">}</span></li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">?>
-
Ich weiß nicht was ich falsch mache! xD
-
session_start(); muss immer ganz am anfang stehen, davor darf nichts sein (nicht mal eine leerzeile, ein <html>-tag o.ä.)
-
Klapt immer noch nicht, das Problem ist eben dass der erste user in der mysql-Datenbank überprüft wird sonst keiner. Ich schätze dass es am while befehl liegt aber ich hab keine ahnung was der fehler ist. :cry_fox:
EDIT:
Hat sich erledigt. Neues Problem: Die while schleife geht auch weiter wenn der user schon angemeldet ist!:
- [url=http://www.php.net/mysql_fetch_array]mysql_fetch_array[/url]( $db_erg, MYSQL_ASSOC)) {
- [url=http://www.php.net/if]if[/url] (($_GET['username']==$zeile['username']) AND ($_GET['passwort']==$zeile['passwort'])) {
-
- $_SESSION['angemeldet'] = 'ja';
-
- }[url=http://www.php.net/echo]echo[/url] ' <font color="red">Logindaten sind falsch!</font>';
- }
- }
-
- [url=http://www.php.net/echo]echo[/url] $zeile['übermich'];
- [url=http://www.php.net/echo]echo[/url] $inhalt;
- [url=http://www.php.net/echo]echo[/url] '<a href="msql-logout.php">Logout</a>';
- exit;
- }[url=http://www.php.net/echo]echo[/url] '
- <form action="mysql-passwortg.php" method=get enctype="text/plain">
-
- <input type="Text" name="username" value="" size="30" maxlength="50">
-
- <br />
- <br />
-
- <input type="password" name="passwort" value="" size="30" maxlength="50">
-
- <br />
- <br />
-
- <input type="Submit" name="login" value="Login">
-
- </form>';
- }
- }
- exit;
Brauche dringend hilfe! Ich habe schon alles ausprobiert. :()
-
Schon mit break; anstelle von exit; in der Schleife probiert?
-
Ja aber es ändert nichts daran dass das Loginfeld drei mal oder mehr(abhängig von anzahl an usern) angezeigt wird. :cry_fox:
-
kein wunder, du hast schließlich die ausgabe des formulars IN der while-schleife...
-
Ja ich weiß aber ich weiß nicht wie ichs anders machen könnte. =D
-
schließ die schleife einfach vorher und häng das formular NACH der schleife nochmal an ( mit if($_SESSION...) natürlich!)
-
session_start(); muss immer ganz am anfang stehen, davor darf nichts sein (nicht mal eine leerzeile, ein <html>-tag o.ä.)
Wollte ich nochmal korrigieren, wie es oben stand war es vollkommen korrekt
korrekt:
- <?php</li><li style="" class="li2">session_start();</li><li style="" class="li1">?>
- <?php</li><li style="" class="li2">// oh hai</li><li style="" class="li1">session_start();</li><li style="" class="li2">?>
- <?php</li><li style="" class="li2">$yay = "a chiken";</li><li style="" class="li1">session_start();</li><li style="" class="li2">?>
nicht korrekt:
(Fehler: HTTP-Headers already sent. Sobald die erste Zeile Text rausgeht werden natürlich auch die Header verschickt)
[Meh, das Beispiel mit der Leerzeile will der mir net machen, wird aus dem Code-Tag rausgetrimmt]
- <!-- Kommentar zählt manchmal doch -->
- <?php</li><li style="" class="li1">session_start();</li><li style="" class="li2">?>
- <html>
- <?php</li><li style="" class="li1">session_start();</li><li style="" class="li2">?>