Punten aantal genoeg?

Gestart doorRiick43 reacties119 weergaven

44 berichten · pagina 2 van 3

Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb dit via een tutorial voor mekaar gekregen.
Maar nu echot hij de punten aantallen van iedereen...
Hoe doe ik dat hij het alleen van de gebruiker van de huidige sessie doet?

[COLOR= #0000BB]<?php
$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT uCoins FROM member_accounts"[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700])) {[/COLOR] 
  [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$obj[/COLOR][COLOR= #007700]->[/COLOR]uCoins[COLOR= #007700].[/COLOR][COLOR= #DD0000]" "[/COLOR][COLOR= #007700]; 
}[/COLOR] 
[URL="http://www.php.net/mysql_free_result"]mysql_free_result[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700]);[/COLOR] 
?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Geen fetch_object gebruiken... Gebruik mysql_fetch_assoc.
Je geeft geen where mee aan je database.
Mysql_free_result is niet nodig.
Waarom . " "; achter je string?

[COLOR= #0000BB]<?php
$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT uCoins FROM member_accounts WHERE uName = hierdenaam"[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700])) {[/COLOR] 
  [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]uCoins[/COLOR][COLOR= #007700]];
}[/COLOR] 
?>
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat is er verkeerd aan fetch_object als ik vragen mag?
en hoe doe ik het om

uName = hierdenaam");


Te vervangen met de huidige sessie?
Zelf dacht ik aan

uName = $_SESSION[uId]");


Is dit correct?

toevoeging op 26 februari 2013, 18:33:37:
Als ik het toepas krijg ik een blanco pagina.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
uId = " . $_SESSION[uId]);


Leer aub eerst de basis voor je vragen gaat stellen. Dit zijn namelijk echt basisdingen die je vraagt.
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waar kan ik dit gedeelte vinden?
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
MySQL en PHP Sessions.

Bijvoorbeeld:
http://www.tizag.com/phpT/ / http://www.tizag.com/mysqlTutorial/

Maar er zijn zat andere sites en boeken te vinden. Zolang je maar een beetje recente tutorials pakt. Dus geen tutorials die PHP 4.x gebruiken. We zitten al bijna tegen de PHP 6 aan inmiddels emo
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik kan het er echt niet uit opmaken...
Voor mijn gevoel zover ik kom is dit correct, maar ik krijg een error.

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]config.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT uCoins FROM member_accounts WHERE uId = . $_SESSION[uId]"[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700])) {[/COLOR] 
  [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]uCoins[/COLOR][COLOR= #007700]];
}[/COLOR] 
?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Kijk nou eens goed naar de code highlighting, en kijk nog eens goed naar wat ik gepost had hier
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oow sorry, ik heb er overheen gelezen.
Bedankt voor het helpen, het is me gelukt.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Rhamz schreef:
@Aarclay, ja tis een voorbeeld hé. Wil niet alles voorkauwen. als ie een beetje gaat googlen dan vind ie de andere mogelijkheden wel.

Prima, maar als je iemand iets aanleert, leer het dan goed aan i.p.v. slechte voorbeelden te geven.
toevoeging op 26 februari 2013, 19:05:59:
Riick schreef:
Oow sorry, ik heb er overheen gelezen.
Mooi zo... En nu door naar de tutorial die ik genoemd had.
E.v.t mag je je punten naar mij toe sturen als je wilt wink
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Je mist nog steeds foutafhandeling, voorgekauwde code, maar doe er dan ook wat mee:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]config.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT uCoins FROM member_accounts WHERE uId = . $_SESSION[uId]"[/COLOR][COLOR= #007700]);[/COLOR] 

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]==[/COLOR] false[COLOR= #007700]) {[/COLOR]

  [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Query mislukt[/COLOR][COLOR= #007700];

}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]

  [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700])) {[/COLOR] 
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]uCoins[/COLOR][COLOR= #007700]];
  }

}[/COLOR]
?>
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
En i.p.v. van Query mislukt kan je ook mysql_error() er bij tonen. Zorg er dan het liefste voor dat die errors alleen te zien zijn voor jouw, en niet voor anderen.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Tevens is het ook wenselijk om van MySQLi gebruik te maken, daar heb je namelijk ook prepared statements.

Verder: query is lek.
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Raaoul schreef:
Je mist nog steeds foutafhandeling, voorgekauwde code, maar doe er dan ook wat mee:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]config.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT uCoins FROM member_accounts WHERE uId = . $_SESSION[uId]"[/COLOR][COLOR= #007700]);[/COLOR] 

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR] [COLOR= #007700]==[/COLOR] false[COLOR= #007700]) {[/COLOR]

  [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Query mislukt[/COLOR][COLOR= #007700];

}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]

  [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$res[/COLOR][COLOR= #007700])) {[/COLOR] 
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]uCoins[/COLOR][COLOR= #007700]];
  }

}[/COLOR]
?>
Parse error: syntax error, unexpected  (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) on line 3


---

@Raaoul wat bedoel je met query is lek?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
sql injection, bij je session.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren