Dobrý deň, programujem v PHP nie objektovo. Potreboval by som do scriptov dať execute a prepared dodávam tu script. Okrem toho by ste mi vedeli upraviť int1-8? vraj sa to dá krásne zapísať cez foreach.
<?php if(isset($_POST['register'])){
$username = mysqli_real_escape_string($con, $_POST['username']);
$username = htmlspecialchars( $username );
$password = mysqli_real_escape_string($con, $_POST['password']);
$password = htmlspecialchars( $password );
$email= mysqli_real_escape_string($con, $_POST['email']);
$email = htmlspecialchars( $email );
if($username == "" || $password == "" || $email == ""){
echo "Na niečo si zabudol!";
}elseif(strlen($username) > 20){
echo "Tvoje meno je veľmi dlhé!";
}elseif(strlen($email) > 100){
echo "Tvoj e-mail je veľmi dlhý!";
}else{
$register1 = mysqli_query($con,"SELECT `id` FROM `user` WHERE `username`='$username'") or die(mysqli_error());
$register2 = mysqli_query($con,"SELECT `id` FROM `user` WHERE `email`='$email'") or die(mysqli_error());
if(mysqli_num_rows($register1) > 0){
echo "Toto meno je už používané!";
}elseif(mysqli_num_rows($register2) > 0){
echo "Tento e-mail je už používaný!";
}else{
if($_POST['frakcia'] == "USA"){ $frakcia = 0; }
elseif($_POST['frakcia'] == "Nemecko"){ $frakcia = 1;
}
if($_POST['frakcia'] == "Slovensko"){ $frakcia = 2; }
elseif($_POST['frakcia'] == "ZSSR"){ $frakcia = 3;
}
if($_POST['frakcia'] == "Taliansko"){ $frakcia = 4; }
elseif($_POST['frakcia'] == "Británia"){ $frakcia = 5;
}
$code = generate_code();
$ins1 = mysqli_query($con,"INSERT INTO `stats` (`gold`,`attack`,`defense`,`food`,`income`,`farming`,`battery`,`rank`,`floor`,`quest`,`qok`,`wall`,`cannon`,`ccost`,`cattack`,`wcost`,`wdefense`,`username`,`inv`,`new`,`guild`,`apotion`,`dpotion`) VALUES (100,0,0,200,0,0,100,0,1,1,0,0,0,1000,0,1250,0,'$username',0,0,0,0,0)") or die(mysqli_error($con));
$ins2 = mysqli_query($con,"INSERT INTO `unit` (`worker`,`farmer`,`rifleman`,`machinegunner`,`tfarmer`,`dog`,`fisherman`,`soldier`,`sergeant`,`gendef`,`schutze`,`soldad`,`maschinengewehr`,`leutant`,`hauptmann`,`hund`,`strelec`,`gulometcik`,`vojak`,`serzant`,`generalobrany`,`pes`,`strelets`,`pistoleti`,`vojnik`,`sershant`,`obscht`,`kuce`,`tiratore`,`artigliere`,`soldato`,`sergente`,`generale`,`enfieldman`,`gunner`) VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)") or die (mysqli_error());
$ins3 = mysqli_query($con,"INSERT INTO `user` (`username`,`password`,`email`,`fraction`,`activated`,`code`) VALUES ('$username', '".sha1($password)."', '$email', '$frakcia', 1, '$code')") or die (mysqli_error());
$ins4 = mysqli_query($con,"INSERT INTO `weapon` (`springfield`,`m1garand`,`browning`,`pershing`,`hellcat`,`sherman`,`thompson`,`kar98`,`mp40`,`gw43`,`mp44`,`mg42`,`m1a1`,`tiger`,`stugv`,`tiger2`,`howitzer`,`panzerstellung`,`pps43`,`pps41`,`mp38`,`zk383`,`gulometvz24`,`puskavz24`,`pak38`,`flak37`,`grw`,`lt38`,`enfield`,`sten`,`bren`,`bar`,`delisle`,`lewis`,`vickers`,`cromwell`,`comet`,`carcano`,`skoda`,`brixia`,`breda`,`ovp`,`baretta`,`fucile`,`p43`,`carro`,`mosinnagant`,`minometvz40`,`maxim`,`kv2`,`dp27`,`zis3`,`t34`,`is2`,`svt40`) VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)") or die (mysqli_error());
$ins5 = mysqli_query($con,"INSERT INTO `working` (`fyes`,`myes`,`bonus`,`ayes`,`fwork`,`mwork`,`tfwork`,`tyes`,`fishermanwork`,`adyes`,`ad2yes`) VALUES (0,0,0,0,0,0,0,0,0,0,0)") or die (mysqli_error());
$ins6 = mysqli_query($con,"INSERT INTO `ranking` (`number`) VALUES (0)") or die (mysqli_error());
$ins7 = mysqli_query($con,"INSERT INTO `timer` (`ftime`,`mtime`,`atime`,`adtime`,`ad2time`) VALUES (0,0,0,0,0)") or die (mysqli_error());
$ins8 = mysqli_query($con,"INSERT INTO `daily` (`bonus`) VALUES (0)") or die (mysqli_error());
echo "Si úspešne zaregistrovaný!";
$t = file_get_contents("registracie.txt");
$today = date("Y-m-d H:i:s");
$t .= $today." Používateľ ".$username." "."sa zaregistroval!"."\r\n";
file_put_contents("registracie.txt",$t);
mail($email,"Nation Wars: ","Vítaj v hre Nation Wars!\r\n\r\nPrihlásovacie meno: ".$username."\r\n");
}
}
}}
?>
HTML form:
<form action="register.php" method="post">
<input type="text" name="username" class="inputbox" alt="username" placeholder=Meno style="width:100%" />
<input type="password" name="password" class="inputbox" size="18" alt="password" placeholder=Heslo style="width:100%" />
<input id="modlgn_username" type="text" name="email" class="inputbox" alt="email" placeholder=E-mail style="width:100%" />
</p>
<script>
var vlajkaa = {
"USA" : "images/fraction0.png",
"Nemecko" : "images/fraction1.png",
"Slovensko" : "images/fraction2.png",
"ZSSR" : "images/fraction3.png",
"Taliansko" : "images/fraction4.png",
"Británia" : "images/fraction5.png"
};
var infoo = {
"USA" : "Spojenci",
"Nemecko" : "Osa",
"Slovensko" : "Osa",
"ZSSR" : "Spojenci",
"Taliansko" : "Osa",
"Británia" : "Spojenci"
};
</script>
Frakcia:
<select name="frakcia" onchange="document.getElementById('vlajka').src = vlajkaa[this.value]; document.getElementById('info').innerHTML = infoo[this.value];">
<option value="USA">USA</option>
<option value="Nemecko">Nemecko</option> >
<option value="Slovensko">Slovensko</option>>
<option value="ZSSR">ZSSR</option>
<option value="Taliansko">Taliansko</option>
<option value="Británia">Británia</option>
</select>
<br />
Vojnová politika:
<b>
<font id="info" style="color: #00cc66">Spojenci</font>
</b>
<img src="images/fraction0.png" id="vlajka" style="width: 64px; height: 69px;"/>
<i></i>
<br>
<button type="submit" name="register" class="xmiddle green button round">Registrovať!</button>
<hr> Registráciou súhlasíte s <a href="blog/podmienky.php">podmienkami hry! </a>
<ul>
<li>
<a href="index.php">Prihlásiť sa do účtu</a>
</li>
</ul>
</form>