The following script draws 6 numbers at random.I input another 6 numbers and compare with random numbers generated, if they're the same, you win.     <html><body><form align=center action=<?php echo htmlspecialchars($_SERVER[PHP_SELF]);?> method=post>Numele jucatorului <input type=text name=nume min=1 max=10 required=yes><br><br>Numar 1: <input type=number name=nr1 min=1 max=49 required=yes><br><br>Numar 2: <input type=number name=nr2 min=1 max=49 required=yes><br><br>Numar 3: <input type=number name=nr3 min=1 max=49 required=yes><br><br>Numar 4: <input type=number name=nr4 min=1 max=49 required=yes><br><br>Numar 5: <input type=number name=nr5 min=1 max=49 required=yes><br><br>Numar 6: <input type=number name=nr6 min=1 max=49 required=yes><br><br><input type=submit><br><form><?php#error_reporting(0);$server = ;$user = ;$password = ;$conectare = new mysqli($server, $user, $password);if ($conectare->connect_error){        die(Conexiune esuata: . $conectare->connect_error);}$name = htmlspecialchars($_POST[nume]);$rn1 = htmlspecialchars($_POST[nr1]);$rn2 = htmlspecialchars($_POST[nr2]);$rn3 = htmlspecialchars($_POST[nr3]);$rn4 = htmlspecialchars($_POST[nr4]);$rn5 = htmlspecialchars($_POST[nr5]);$rn6 = htmlspecialchars($_POST[nr6]);echo <br>Salut  . $name . !<br>;echo <br>Numerele introduse sunt: . $rn1 .   . $rn2 .   . $rn3 .   . $rn4 .   . $rn5 .   . $rn6 . <br>;$numere = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49);$random = array_rand($numere, 6);$nr1 = $numere[$random[0]];$nr2 = $numere[$random[1]];$nr3 = $numere[$random[2]];$nr4 = $numere[$random[3]];$nr5 = $numere[$random[4]];$nr6 = $numere[$random[5]];$extrase = array($nr1, $nr2, $nr3, $nr4, $nr5, $nr6);echo Numerele extrase sunt: . $nr1 .   . $nr2 .   . $nr3 .   . $nr4 .   . $nr5 .   . $nr6 . <br>;if ($nr1 == $rn1 or $nr1 == $rn2 or $nr1 == $rn3 or $nr1 == $rn4 or $nr1 == $rn5 or $nr1 == $rn6){        echo Castigator : $nr1  ;}if ($nr2 == $rn1 or $nr2 == $rn2 or $nr2 == $rn3 or $nr2 == $rn4 or $nr2 == $rn5 or $nr2 == $rn6){        echo Numar castigator : $nr2  ;}if ($nr3 == $rn1 or $nr3 == $rn2 or $nr3 == $rn3 or $nr3 == $rn4 or $nr3 == $rn5 or $nr3 == $rn6){        echo Numar castigator : $nr3  ;}if ($nr4 == $rn1 or $nr4 == $rn2 or $nr4 == $rn3 or $nr4 == $rn4 or $nr4 == $rn5 or $nr4 == $rn6){        echo Numar castigator : $nr4  ;}if ($nr5 == $rn1 or $nr5 == $rn2 or $nr5 == $rn3 or $nr5 == $rn4 or $nr5 == $rn5 or $nr5 == $rn6){        echo Numar castigator : $nr5  ;}if ($nr6 == $rn1 or $nr6 == $rn2 or $nr6 == $rn3 or $nr6 == $rn4 or $nr6 == $rn5 or $nr6 == $rn6){        echo Numar castigator : $nr6  ;}?></body></html>
Lotto/lucky draw
php;html;random
There are a number of things you can do to improve your code.You should try to seperate your logic from your html. In larger applications this will mean seprate files (probably following an MVC convention), but for small scripts like this simply placing your logic at the top of the file before the html is a good idea.You need to use a conditional check to make sure the form has been posted before trying to access the posted values. This can be done by checking the $_SERVER['REQUEST_METHOD'] variable.Instead of using individual form field names for related data, you can use the array syntax name=somename[] note the square braces. Then php will gather the data from the separate fields into a single array held in $_POST['somename'].Builing on from @Quill's answer, you can simplify the generation of the random answers further by using array_flip to transpose the result of range into an array indexed from 1-49 then use the keys returned by array_rand directlyYou can simplify calculating matching results by using array_interect to retrieve an array for matchesPutting this all together:<?php$showResults = false;if($_SERVER['REQUEST_METHOD']=='POST'){    $showResults = true;    $name = $_POST['nume'];    $answers = $_POST['nr'];    $randomAnswers = array_rand(array_flip(range(1, 49)), 6);    $matches = array_intersect($answers, $randomAnswers);    $numberOfMatches = count($matches);}?><html><head></head><body>    <form action=<?php echo htmlspecialchars($_SERVER[PHP_SELF]);?> method=post>        Your name: <input type=text name=nume min=1 max=10 required=yes><br>        <br>        Number 1: <input type=number name=nr[] min=1 max=49 required=yes><br>        <br>        Number 2: <input type=number name=nr[] min=1 max=49 required=yes><br>        <br>        Number 3: <input type=number name=nr[] min=1 max=49 required=yes><br>        <br>        Number 4: <input type=number name=nr[] min=1 max=49 required=yes><br>        <br>        Number 5: <input type=number name=nr[] min=1 max=49 required=yes><br>        <br>        Number 6: <input type=number name=nr[] min=1 max=49 required=yes><br>        <br>        <input type=submit>        <br>    <form>        <?php        if($showResults):?>            <p>Hello <?php echo $name;?>!<p>            <p>Your lotto numbers are: <?php echo implode(' ', $answers);?></p>            <p>The winning numbers are: <?php echo implode(' ', $randomAnswers);?></p>            <p>You matched (<?php echo $numberOfMatches;?>) numbers</p>            <?php            if($numberOfMatches == 6):?>                <h1>Congratulations you won the Lotto!</h1>            <?php            endif;        endif;        ?></body></html>