Jump to content
php.lv forumi

"if" iekš "if"


Chapman

Recommended Posts

es zinu, ka tas, laikam, nav pareizi, bet man ir if operators iekš cita if.

kods:


if (isset($_POST['login_start'])){
// Connect to server and select databse.
mssql_connect("$host", "$username", "$password")or die("cannot connect");
mssql_select_db("SecKeyPrior")or die("cannot select DB");

// username and password sent from form
$nick=$_POST['Nick'];
$pw=$_POST['passw'];

// To protect MySQL injection (more detail about MySQL injection)
$nick = stripslashes($nick);
$pw= stripslashes($pw);


$sql="SELECT Id, Nick, pw, Locked, Error, F_Name, S_Name   FROM S_Users WHERE Nick='$nick'  and pw='$pw'";
$result=mssql_query($sql);
$result2 = mssql_fetch_row($result);
$blocked = $result2[3];
$errors = $result2[4];
if ( $blocked == '1' )
{
$lockerror = "<div align=center> Tavs lietotājs ir bloķēts!</div>";
}
else{
// Mysql_num_row is counting table row
$count=mssql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
//autorizācijas parbaude
if($count==1){
$dati = "SELECT Id, F_Name, S_name, Nick, Is_Admin   FROM S_Users WHERE Nick='$nick'  and pw='$pw'";
$dati = mssql_query( $dati );
$dati = mssql_fetch_row($dati);
$id = $dati[0];
$Vards = $dati[1];
$Uzvards = $dati[2];
$niks = $dati[3];
$admin = $dati[4];

setcookie("id", $id, time() + 3600);
setcookie("Vards", $Vards, time() + 3600);
setcookie("Uzvards", $Uzvards, time() + 3600);
setcookie("Niks", $niks, time() + 3600);
setcookie("Admin", $admin, time() + 3600);
header("location: ?dome=main");
}
else {
$logerror = "<div align=center> Lietotājvārds un/vai parole nav pareizi ievadīta</div>";
mssql_query 
(
	"Use SecKeyPrior
	UPDATE S_Users
	SET Error = Error+'1'
	WHERE Nick = '$nick' " 
);
if ( $errors > '3' )
{
mssql_query 
(
"Use SecKeyPrior
UPDATE S_Users
SET Locked = 'True'
WHERE Nick = '$nick'"
);
}
}
}
}

 

es nesaprotu kāpēc man neizpildās tieši šī koda daļa:

mssql_query 
(
"Use SecKeyPrior
UPDATE S_Users
SET Locked = 'True'
WHERE Nick = '$nick'"
);

Edited by Chapman
Link to comment
Share on other sites

1) katrā if/while/... kodu liec ar atkāpi (parasti tab - 4x atstarpes). tā vieglāk lasīt blokus, uztvert loģiku, kur kas sākas un beidzas

 

2) else attiecas uz tuvāko if. ja tev nupat beidzas viens iekšējais if un tu gribi, lai else attiecas nevis to, bet uz ārējo if, tad ieliec vēl vienu }

if () {
if () {
	...
}
else {
	...
}
}

if () {
if () {
	...
}
}
else {
...
}

pamanīji atšķirību?

 

es neteikšu priekšā, bet sakārtojot kodu, tev pašam atnāks apskaidrība ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...