didy Posted April 17, 2009 Report Share Posted April 17, 2009 (edited) <?php if ($_POST){ $error = ""; if($_POST['a1'] == ""){ $error ="nr1 FALSE<br />"; } if($_POST['a2'] == ""){ $error ="nr2 FALSE<br />"; } if($_POST['a3'] == ""){ $error ="nr3 FALSE<br />"; } if ($error != ""){ echo "$error"; }else { echo $_POST['a1']; echo $_POST['a2']; echo $_POST['a3']; } }else{ ?> <form method="POST" action="/index.php"> a1<input type="text" name="a1" /><br /> a2<input type="text" name="a2" /><br /> a3<input type="text" name="a3" /><br /> <input type="submit" name="submit" /> </form> <?php } ?> Velos lai $error izdruka visas kludas, nevis tikai vienu! Pemeram ja netiek aizpildiits a1 un a2. Gribu lao mainigais $error izdruka kludu par abiem. Ka to panakt, nepieskirot katrai kludas izdrukai savu mainigo!? Edited April 17, 2009 by didy Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted April 17, 2009 Report Share Posted April 17, 2009 (edited) ... $error=array(); ... $error[] ="nr1 FALSE<br />"; ... $error[] ="nr2 FALSE<br />"; ... $error[] ="nr3 FALSE<br />"; ... echo implode('',$error); ... Edited April 17, 2009 by xPtv45z Quote Link to comment Share on other sites More sharing options...
Aikss Posted April 17, 2009 Report Share Posted April 17, 2009 Virknes beigās liek katru jaunu kļūdu: $errors = ''; $errors .= 'abc'; $errors .= '123'; echo $errors; // abc123 Kļūdas liek masīvā: $errors = array(); $errors[] = 'abc'; $errors[] = '123'; // array('abc', '123') foreach($errors as $error) { echo $error; } Ja lietosi <br /> tad liec virknē, ja gribi izvadīt kā sarakstu <ul><li></li></ul> vai ko vairāk ar tām kļūdām darīt, vari lietot masīvu. Quote Link to comment Share on other sites More sharing options...
didy Posted April 17, 2009 Author Report Share Posted April 17, 2009 Paldies Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.