mysql si robi co chce

Programovacie jazyky, rady, poradňa...
turtlak69
Guru
Guru
Príspevky: 2896
Registrovaný: 10 máj 2007, 15:58
Bydlisko: /dev/null

mysql si robi co chce

Príspevok od používateľa turtlak69 »

je to divne, ale je to tak. robil som registraciu. vsetko funguje bezchybne, ale obcas to zblbne. neviem ako je to mozne. obcas sa udaje do DB zapisu a obcas nie. co je horsie, ja tu chybu neviem ani simulovat. stalo sa to za jeden den dvom ludom a ostatnym nie. do DB sa zapise uzivatelske meno, heslo, mail, datum registracie vzdy. nebol s tym este problem ani raz. ale obcas sa nezapisu udaje o pohlavi a o datume narodenia. ale query sa vykona v pohode a vrati hodnotu true aj ked sa tie udaje nezapisali. neviem ako je to mozne. tu je skript registracie:

Kód: Vybrať všetko

<?php
if (isset($_POST['reg_login']) && ($_POST['reg_pass']) && ($_POST['reg_pass2']) && ($_POST['reg_mail']))
{
$reg_login=htmlspecialchars($_POST[reg_login]);
$reg_pass=htmlspecialchars($_POST[reg_pass]);
$reg_pass2=htmlspecialchars($_POST[reg_pass2]);
$reg_mail=htmlspecialchars($_POST[reg_mail]);
$nonmd5pass=$reg_pass;

//	login

$sql = MySQL_Query("Select * FROM $tab_users WHERE user_login='$reg_login'");
$pocet=Mysql_num_rows($sql);

$sql2 = MySQL_Query("Select * FROM $tab_users WHERE user_mail='$reg_mail'");
$pocet2=Mysql_num_rows($sql2);

	if ($pocet > "0")
	{
	$err_login_exist = "1";
	}
	else
	{
	$err_login_exist = "ok";
	$login=$reg_login;
	}

//	pass

	if (!eregi("[[:alnum:]]{5,15}",$reg_pass))
	{
	$err_pass_lenght = "1";
	}
	else
	{
	$err_pass_lenght = "ok";
	}

	if (!eregi("[[:alnum:]]{5,15}",$reg_pass2))
	{
	$err_pass_lenght = "1";
	}
	else
	{
	$err_pass_lenght = "ok";
	}

	if ($reg_pass != $reg_pass2)
	{
	$err_pass_same = "1";
	}
	else
	{
	$err_pass_same = "ok";
	}

//	mail

	if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"
   	."@([a-z0-9]+([\.-][a-z0-9]+))*$",
   	$reg_mail) )
	{
	$err_mail_syntax = "1";
	}
	else
	{
	$err_mail_syntax = "ok";
	}

	if ($pocet2 > "0")
	{
	$err_mail_exist = "1";
	}
	else 
	{
	$err_mail_exist = "ok";
	}

	if ($err_login_exist == "1" || $err_pass_lenght == "1" || $err_pass_same == "1" || $err_mail_syntax == "1" || $err_mail_exist == "1")
	{
	$main .= "
	$start_header Registrácia $end_header
	<form method='post' action='$home_site/index.php?menu=registration'>
	<table width='300'>
	<tr>
	<td><label>meno:</label></td>
	<td align='right'><input type='text'";
		if ($err_login_exist != "1")
		{
		$main .= "value='$reg_login'";
		}
		$main .= "
 		name='reg_login' /></td>
		</tr>
		<tr>
		<td align='left'><label>heslo:</label></td>
		<td align='right'><input type='password' name='reg_pass' /></td>
		</tr>
		<tr>
		<td align='left'><label>heslo (overenie):</label></td>
		<td align='right'><input type='password' name='reg_pass2' /></td>
		</tr>
		<tr>
		<td align='left'><label>mail:</label></td>
		<td align='right'><input type='text'";
		if ($err_mail_exist != "1" && $err_mail_syntax != "1")
		{
		$main .= " value='$reg_mail' ";
		}
		$main .= "
 		name='reg_mail' /></td>
		</tr>
		<tr>
		<td align='center' colspan='2'><br /><input type='submit' value='OK' /></td>
		</tr>";
		

		if ($err_login_exist == "1")
		{
		$main .= "
		<tr>
		<td colspan='2'><br />Zadané meno je už obsadené</td>
		</tr>";
		}

		if ($err_pass_lenght == "1")
		{
		$main .= "
		<tr>
		<td colspan='2'><br />Dĺžka hesla músí byť 5-15 znakov</td>
		</tr>";
		}
	
		if ($err_pass_same == "1")
		{
		$main .= "
		<tr>
		<td colspan='2'><br />Heslá sa nezhodujú</td>
		</tr>";
		}

		if ($err_mail_syntax == "1")
		{
		$main .= "
		<tr>
		<td colspan='2'><br />mail musí byť zadaný v tvare [email protected] ([email protected])</td>
		</tr>";
		}

		if ($err_mail_exist == "1")
		{
		$main .= "
		<tr>
		<td colspan='2'><br />Tento mail používa niekto iný</td>
		</tr>";
		}

	$main .="
	</table>
	</form>
	";
	}

	if ($err_login_exist == "ok" && $err_pass_lenght == "ok" && $err_pass_same == "ok" && $err_mail_syntax == "ok" && $err_mail_exist == "ok")
	{

	$reg_pass=md5($reg_pass);
	$reg_pass=md5($reg_pass);

	$keygen1 = substr (MD5(uniqid(rand(),1)), 10, 5);
	$keygen2 = substr (MD5(uniqid(rand(),1)), 12, 8);
	$auth = "$keygen1-$keygen2";
	$datetime = date("Y:m:d"); // 10-kovy format
	$m=$_POST['edit_birth_month'];
	$y=$_POST['edit_birth_year'];
	$d=$_POST['edit_birth_day'];
	$sex=$_POST['reg_sex'];
	
	$ok1=mysql_query("INSERT INTO $tab_users (user_login, user_pass, user_sex, user_mail, user_birth_day, user_birth_month, user_birth_year, user_reg_date, user_auth, user_status) VALUES ('$reg_login', '$reg_pass', '$sex', '$reg_mail', '$d', '$m', '$y', '$unix_time_now', '$auth', 'n')");


	$subject="$home_subject - registrácia";
	$body="<html>
	<head></head>
	<body>
	Ahoj <b>$reg_login</b>,
	<br><br>
	pre dokončenie registrácie klikni na link <br><a href='$home_site/activate.php?hash=$auth'>$home_site/activate.php?hash=$auth</a> <br>
	<br>
	Tvoje registračné úudaje:<br>
	<br>
	meno:	<b>$reg_login</b><br>
	heslo:	<b>$nonmd5pass</b><br>
	<br>
	prihlásiť sa môžeš zo stránky <a href='$home_site/index.php'>nightlife.namieru.org/index.php</a>
	$mail_footer
	</body>
	</html>
	";

	send_mail($reg_mail,$subject,$body);

		if ($ok1)
		{
		header ("Location: $home_site/index.php?menu=result&result=reg_ok&mail=$reg_mail");
		}

		else 
		{
		header ("Location: $home_site/index.php?menu=result&result=system_failed");
		}
	}
}

else {
$main .= "
$start_header Registrácia $end_header
<form method='post' action='$home_site/index.php?menu=registration'>
<table width='300'>
<tr>
<td><label>meno:</label></td>
<td align='right'><input type='text' name='reg_login' /></td>
</tr>
<tr>
<td align='left'><label>heslo:</label></td>
<td align='right'><input type='password' name='reg_pass' /></td>
</tr>
<tr>
<td align='left'><label>heslo (overenie):</label></td>
<td align='right'><input type='password' name='reg_pass2' /></td>
</tr>
<tr>
<td align='left'><label>e-mail:</label></td>
<td align='right'><input type='text' name='reg_mail' /></td>
</tr>
<tr>
<td align='left'><label>pohlavie:</label></td>
<td align='right'>Muž<input type='radio' value='muž' name='reg_sex' checked /><br />
Žena<input type='radio' value='žena' name='reg_sex' />
</td>
</tr>
<tr>
<td align='left'><label>dátum narodenia <br />(po registrácií nemeniteľný):</label></td>
<td align='right'>";

$main .= "<select name='edit_birth_day'>";
$main .= print_check(edit_birth_day,select);
$main .= "</select>";
$main .= "<select name='edit_birth_month'>";
$main .= print_check(edit_birth_month,select);
$main .= "</select>";
$main .= "<select name='edit_birth_year'>";
$main .= print_check(edit_birth_year,select);
$main .= "</select>";
$main .= "
</td>
</tr>
<tr>
<td align='center' colspan='2'><br /><input type='submit' value='OK' /></td>
</tr>
</table>
</form>

";
}
?>
toto je includnute na index.php. v index.php je aj includnuty skript na pripojenie do DB aj funkcie. prosim poradte, co s tym je :cry:
Shrekzv
Star
Star
Používateľov profilový obrázok
Príspevky: 645
Registrovaný: 24 nov 2005, 18:07
Bydlisko: Zvolen
Kontaktovať používateľa:

Príspevok od používateľa Shrekzv »

Sorry za OT .....ale na zazraky si musis zvyknut :lol: :lol: ..mne napr forum urobilo 70 000 sql dotazov za 10 minut.....ties nechapem co sa stalo....nic som nerobil...a slo potom dalej ok...len malo nejaku blbu chvilku asi :lol: :lol:
turtlak69
Guru
Guru
Príspevky: 2896
Registrovaný: 10 máj 2007, 15:58
Bydlisko: /dev/null

Príspevok od používateľa turtlak69 »

uz sa stretol so vselicim, ale toto este nie. keby som vedel tu chybu aspon simulovat, tak by to nebol az taky problem, ale ked nastane ako jeden z 10 pripadov, tak neviem s tym pohnut. ale vyriesil som to. pri prihlaseni sa overi, ci je su zadane tie udaje, co boli potrebne pri regsitracii a ked nie, tak to presmeruje po lognuti na formular, kde to treba opatovne zadat. tam to asi tu chybu robit nebude. a ked sa ani tam nezapisu udaje niekedy, tak po dalsom lognuti to znovu vypyta. myslim, ze takto to bude najlepsie.
Napísať odpoveď