Jump to content
php.lv forumi

kļūda kodā


epro

Recommended Posts

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... :/

Link to comment
Share on other sites

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 by codez
Link to comment
Share on other sites

×
×
  • Create New...