epro Posted July 12, 2008 Report Posted July 12, 2008 Kods: if(isset($_POST['username']) and isset($_POST['password'])) { $username = quote_smart($_POST['username']); $password = quote_smart(md5($_POST['password'])); $result = mysql_query("SELECT COUNT(*) FROM lietotaji WHERE niks = $username AND parole = $password"); if(mysql_result($result,0,'COUNT(*)') > 0) { #ieliek sesiju $_SESSION['ielogojies'] = 1; $id = mysql_result(mysql_query("SELECT id FROM lietotaji WHERE niks = $username AND parole = $password"),0,'id'); $_SESSION['mans_id'] = $id; } } Parādās errors: Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/users/public_html/mape/index.php on line 17 17 rindiņa sanāk: if(mysql_result($result,0,'COUNT(*)') > 0) Konekcija notiek, uz localhost viss darbojas, uz hosta ne, kas varētu būt pa vainu, caur html formu dati tiek padoti. Tiešām nesaprotu, kapēc neieliek sessiju.. :/ Varbūt kāds zin, kur vaina un kapēc uz localhosta iet bez uz hosta ne... :/
martins256 Posted July 12, 2008 Report Posted July 12, 2008 uz hosta ir attiecīgā tabula uzlikta ? vispār db esi pieslēdzies ? nav db config no localhost ?
codez Posted July 12, 2008 Report Posted July 12, 2008 (edited) Vajag pārbaudīt vai kverijs vispār ir atgriezis rezultātu. To var darīt aptuveni šādi: $result = mysql_query('SELECT * WHERE 1=1') or die('Invalid query: ' . mysql_error()); vai $result = mysql_query('SELECT * WHERE 1=1'); if (!$result) { die('Invalid query: ' . mysql_error()); } Vēl viena lieta, tu divas reizes teisi vienu un to pašu kveriju, es darītu aptuveni šādi šajā gadījumā if(isset($_POST['username']) and isset($_POST['password'])) { $username = quote_smart($_POST['username']); $password = quote_smart(md5($_POST['password'])); $result = mysql_query("SELECT id FROM lietotaji WHERE niks = $username AND parole = $password") or die(mysql_error()); if($user=mysql_fetch_assoc($result) ) { #ieliek sesiju $_SESSION['ielogojies'] = 1; $_SESSION['mans_id'] = $user['id']; } } Edited July 12, 2008 by codez
epro Posted July 12, 2008 Author Report Posted July 12, 2008 Paldies visiem, codez'am vēl jo vairāk, ar tavu variantu viss aizgāja + vēl 1 kveriju ietaupīju.. :) PALDIES
Recommended Posts