<?	
include ('logue.php'); 
include ('entete2.php');

$sql = "SELECT pts,silo_lvl,techenergie_lvl,techenergie_evolution,techlaser_lvl,techlaser_evolution,techions_lvl,techions_evolution,techplasma_lvl,techplasma_evolution,techordi_lvl,techordi_evolution,techcombustion_lvl,techcombustion_evolution,techAsgaards_lvl,techAsgaards_evolution,techhyperespace_lvl,techhyperespace_evolution,techespio1_lvl,techespio1_evolution,techespio2_lvl,techespio2_evolution,techArmement_lvl,techArmement_evolution,techBouclier_lvl,techBouclier_evolution,techcoque_lvl,techcoque_evolution,techproAsgaard_lvl,techproAsgaard_evolution,techproAncien_lvl,techproAncien_evolution,techinfra_lvl,techinfra_evolution,technaqua_lvl,technaqua_evolution  FROM matgraph_users WHERE id='$dataid[id]' ";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res); 
$sql2 = "SELECT chantier_lvl,robo_lvl,silo_lvl,hangarfer_lvl,hangarfer_evolution,hangaror_lvl,hangaror_evolution,hangarada_lvl,hangarada_evolution,hangaror_lvl,hangarura_lvl,hangarura_evolution,labo_lvl,labo_evolution,fer_energie,or_energie,ada_energie,ura_energie,exfer_energie,exor_energie,central_energie  FROM matgraph_users WHERE id = '$planete' ";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);

// silo
if ($row2[silo_lvl] =="0") {
$silo_lvl = "0";
}
else {
$silo_lvl = $row2[silo_lvl];
}
// techenergie
if ($row[techenergie_lvl] =="0") {
$techenergie_lvl = "0";
}
else {
$techenergie_lvl = $row[techenergie_lvl];
}
// techlaser
if ($row[techlaser_lvl] =="0") {
$techlaser_lvl = "0";
}
else {
$techlaser_lvl = $row[techlaser_lvl];
}
// techions
if ($row[techions_lvl] =="0") {
$techions_lvl = "0";
}
else {
$techions_lvl = $row[techions_lvl];
}
// techplasma
if ($row[techplasma_lvl] =="0") {
$techplasma_lvl = "0";
}
else {
$techplasma_lvl = $row[techplasma_lvl];
}
// techordi
if ($row[techordi_lvl] =="0") {
$techordi_lvl = "0";
}
else {
$techordi_lvl = $row[techordi_lvl];
}
// techcombustion
if ($row[techcombustion_lvl] =="0") {
$techcombustion_lvl = "0";
}
else {
$techcombustion_lvl = $row[techcombustion_lvl];
}
// techAsgaards
if ($row[techAsgaards_lvl] =="0") {
$techAsgaards_lvl = "0";
}
else {
$techAsgaards_lvl = $row[techAsgaards_lvl];
}
// techhyperespace
if ($row[techhyperespace_lvl] =="0") {
$techhyperespace_lvl = "0";
}
else {
$techhyperespace_lvl = $row[techhyperespace_lvl];
}
// techespio1
if ($row[techespio1_lvl] =="0") {
$techespio1_lvl = "0";
}
else {
$techespio1_lvl = $row[techespio1_lvl];
}
// techespio2
if ($row[techespio2_lvl] =="0") {
$techespio2_lvl = "0";
}
else {
$techespio2_lvl = $row[techespio2_lvl];
}
// techArmement
if ($row[techArmement_lvl] =="0") {
$techArmement_lvl = "0";
}
else {
$techArmement_lvl = $row[techArmement_lvl];
}
// techBouclier
if ($row[techBouclier_lvl] =="0") {
$techBouclier_lvl = "0";
}
else {
$techBouclier_lvl = $row[techBouclier_lvl];
}
// techcoque
if ($row[techcoque_lvl] =="0") {
$techcoque_lvl = "0";
}
else {
$techcoque_lvl = $row[techcoque_lvl];
}
// techproAsgaard
if ($row[techproAsgaard_lvl] =="0") {
$techproAsgaard_lvl = "0";
}
else {
$techproAsgaard_lvl = $row[techproAsgaard_lvl];
}
// techproAncien
if ($row[techproAncien_lvl] =="0") {
$techproAncien_lvl = "0";
}
else {
$techproAncien_lvl = $row[techproAncien_lvl];
}
// techinfra
if ($row[techinfra_lvl] =="0") {
$techinfra_lvl = "0";
}
else {
$techinfra_lvl = $row[techinfra_lvl];
}
// technaqua
if ($row[technaqua_lvl] =="0") {
$technaqua_lvl = "0";
}
else {
$technaqua_lvl = $row[technaqua_lvl];
}
// chantier
if ($row2[chantier_lvl] =="0") {
$chantier_lvl = "0";
}
else {
$chantier_lvl = $row2[chantier_lvl];
}

if (!($techlaser_lvl >= 3)) { $_POST['pclaser'] = 0; }
if (!($techlaser_lvl >= 7)) { $_POST['gclaser'] = 0; }
if (!($techions_lvl >= 5)) { $_POST['pcions'] = 0; }
if (!($techions_lvl >= 8)) { $_POST['gcions'] = 0; }
if (!($techplasma_lvl >= 2)) { $_POST['plplasma'] = 0; }
if (!($techplasma_lvl >= 5)) { $_POST['bplasma'] = 0; }
if (!($techplasma_lvl >= 10)) { $_POST['glplasma'] = 0; }
if (!($technaqua_lvl >= 1 && $techplasma_lvl >= 10)) { $_POST['bnaquadria'] = 0; }
if (!($technaqua_lvl >= 10 && $techplasma_lvl >= 10)) { $_POST['cnaquadria'] = 0; }
if (!($silo_lvl >= 10 && $techplasma_lvl >= 10 && $techproAncien_lvl >= 15)) { $_POST['babel'] = 0; }
if (!($techcombustion_lvl >= 1)) { $_POST['pcombustion'] = 0; }
if (!($techcombustion_lvl >= 3)) { $_POST['gcombustion'] = 0; }
if (!($techAsgaards_lvl >= 1)) { $_POST['pimpulsion'] = 0; }
if (!($techAsgaards_lvl >= 5)) { $_POST['gimpulsion'] = 0; }
if (!($techhyperespace_lvl >= 2)) { $_POST['phyperspatial'] = 0; }
if (!($techhyperespace_lvl >= 5)) { $_POST['ghyperspatial'] = 0; }
if (!($techBouclier_lvl >= 3)) { $_POST['mbouclier'] = 0; }
if (!($techBouclier_lvl >= 7)) { $_POST['champs'] = 0; }
if (!($techBouclier_lvl >= 10)) { $_POST['gbouclier'] = 0; }
if (!($techBouclier_lvl >= 15 && $techproAncien_lvl >= 8)) { $_POST['abouclier'] = 0; }
if (!($techcoque_lvl >= 2)) { $_POST['pcoque'] = 0; }
if (!($techcoque_lvl >= 5)) { $_POST['gcoque'] = 0; }
if (!($techcoque_lvl >= 10)) { $_POST['ccoque'] = 0; }
if (!($techcoque_lvl >= 15 && $technaqua_lvl > 1)) { $_POST['ncoque'] = 0; }

$img = htmlentities ($_POST["img"]);
$nom = htmlentities ($_POST["nom"]);
$description = htmlentities ($_POST["description"]);
$mitraillette_simple = round(htmlentities ($_POST["mitraillette_simple"])); if($mitraillette_simple < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$mitraillette_ameliorer = round(htmlentities ($_POST["mitraillette_ameliorer"])); if($mitraillette_ameliorer < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$pclaser = round(htmlentities ($_POST["pclaser"])); if($pclaser < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$gclaser = round(htmlentities ($_POST["gclaser"])); if($gclaser < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$pcions = round(htmlentities ($_POST["pcions"])); if($pcions < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$gcions = round(htmlentities ($_POST["gcions"])); if($gcions < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$plplasma = round(htmlentities ($_POST["plplasma"])); if($plplasma < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$bplasma = round(htmlentities ($_POST["bplasma"])); if($bplasma < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$glplasma = round(htmlentities ($_POST["glplasma"])); if($glplasma < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$bnaquadria = round(htmlentities ($_POST["bnaquadria"])); if($bnaquadria < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$cnaquadria = round(htmlentities ($_POST["cnaquadria"])); if($cnaquadria < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$babel = round(htmlentities ($_POST["babel"])); if($babel < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$pcombustion = round(htmlentities ($_POST["pcombustion"])); if($pcombustion < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$gcombustion = round(htmlentities ($_POST["gcombustion"])); if($gcombustion < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$pimpulsion = round(htmlentities ($_POST["pimpulsion"])); if($pimpulsion < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$gimpulsion = round(htmlentities ($_POST["gimpulsion"])); if($gimpulsion < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$phyperspatial = round(htmlentities ($_POST["phyperspatial"])); if($phyperspatial < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$ghyperspatial = round(htmlentities ($_POST["ghyperspatial"])); if($ghyperspatial < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$mbouclier = round(htmlentities ($_POST["mbouclier"])); if($mbouclier < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$champs = round(htmlentities ($_POST["champs"])); if($champs < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$gbouclier = round(htmlentities ($_POST["gbouclier"])); if($gbouclier < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$abouclier = round(htmlentities ($_POST["abouclier"])); if($abouclier < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$pcoque = round(htmlentities ($_POST["pcoque"])); if($pcoque < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$gcoque = round(htmlentities ($_POST["gcoque"])); if($gcoque < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$ccoque = round(htmlentities ($_POST["ccoque"])); if($ccoque < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$ncoque = round(htmlentities ($_POST["ncoque"])); if($ncoque < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$fer = htmlentities ($_POST["fer"]); if($fer < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$or = htmlentities ($_POST["or"]); if($or < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$ada = htmlentities ($_POST["ada"]); if($ada < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$ura = htmlentities ($_POST["ura"]); if($ura < 0) { echo '<script language=javascript> alert ("Donnée(s) incorrectes");</script>'; include('creer.php'); exit; }
$place = htmlentities ($_POST["place"]);
$vitesse = htmlentities ($_POST["vitesse"]); 
$coque = htmlentities ($_POST["coque"]);
$bouclier = htmlentities ($_POST["bouclier"]);
$arme = htmlentities ($_POST["arme"]);
$infra = htmlentities ($_POST["infra"]);

if($infra == "1") {
	if($techinfra_lvl >=1 && $chantier_lvl >= 1){
		$place_base = 200;
		$coutfer=300;
		$coutor=300;
		$coutada=20;
		$coutura=5;
		$chantier_lvl = 1;
	}
	else
	{
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("chantier.php");
		-->
		</script>';
		exit;
	}
}
if($infra == "2") {
	if($techinfra_lvl >=2 && $chantier_lvl >= 2){
		$place_base = 9000;
		$coutfer=500;
		$coutor=500;
		$coutada=50;
		$coutura=10;
		$chantier_lvl = 2; 
	}
	else
	{
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("chantier.php");
		-->
		</script>';
		exit;
	}
}
if($infra == "3") {
	if($techinfra_lvl >=4 && $chantier_lvl >= 4){
		$place_base = 15000;
		$coutfer=1200;
		$coutor=1200;
		$coutada=100;
		$coutura=20;
		$chantier_lvl = 4;
	}
	else
	{
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("chantier.php");
		-->
		</script>';
		exit;
	}
}
if($infra == "4") {
	if($techinfra_lvl >=5 && $chantier_lvl >= 5){
		$place_base = 25000;
		$coutfer=4000;
		$coutor=4000;
		$coutada=400;
		$coutura=50;
		$chantier_lvl = 5;
	}
	else
	{
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("chantier.php");
		-->
		</script>';
		exit;
	}
}
if($infra == "5") {
	if($techinfra_lvl >=7 && $chantier_lvl >= 7){
		$place_base = 75000;
		$coutfer=10000;
		$coutor=10000;
		$coutada=1000;
		$coutura=100;
		$chantier_lvl = 7;
	}
	else
	{
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("chantier.php");
		-->
		</script>';
		exit;
	}
}
if($infra == "6") {
	if($techinfra_lvl >=10 && $chantier_lvl >= 10){
		$place_base = 150000;
		$coutfer=15000;
		$coutor=15000;
		$coutada=1500;
		$coutura=200;
		$chantier_lvl = 10;
	}
	else
	{
		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("chantier.php");
		-->
		</script>';
		exit;
	}
}

$verif_fer = $coutfer;
$verif_fer+= $mitraillette_simple*100;
$verif_fer+= $mitraillette_ameliorer*300;
$verif_fer+= $pclaser*1000;
$verif_fer+= $gclaser*1500;
$verif_fer+= $pcions*2000;
$verif_fer+= $gcions*2000;
$verif_fer+= $plplasma*4000;
$verif_fer+= $bplasma*4500;
$verif_fer+= $glplasma*6500;
$verif_fer+= $bnaquadria*12000;
$verif_fer+= $cnaquadria*25000;
$verif_fer+= $pcombustion*100;
$verif_fer+= $gcombustion*350;
$verif_fer+= $pimpulsion*400;
$verif_fer+= $gimpulsion*450;
$verif_fer+= $phyperspatial*500;
$verif_fer+= $ghyperspatial*550;
$verif_fer+= $mbouclier*1500;
$verif_fer+= $champs*3000;
$verif_fer+= $gbouclier*5000;
$verif_fer+= $abouclier*8000;
$verif_fer+= $pcoque*500;
$verif_fer+= $gcoque*1000;
$verif_fer+= $ccoque*2000;
$verif_fer+= $ncoque*5000;
$verif_fer+= $babel*4000000;

$verif_or = $coutor;
$verif_or+= $mitraillette_simple*100;
$verif_or+= $mitraillette_ameliorer*100;
$verif_or+= $pclaser*1000;
$verif_or+= $gclaser*1500;
$verif_or+= $pcions*2000;
$verif_or+= $gcions*2000;
$verif_or+= $plplasma*3500;
$verif_or+= $bplasma*4000;
$verif_or+= $glplasma*6000;
$verif_or+= $bnaquadria*10000;
$verif_or+= $cnaquadria*25000;
$verif_or+= $pcombustion*100;
$verif_or+= $gcombustion*250;
$verif_or+= $pimpulsion*300;
$verif_or+= $gimpulsion*350;
$verif_or+= $phyperspatial*400;
$verif_or+= $ghyperspatial*450;
$verif_or+= $mbouclier*1500;
$verif_or+= $champs*3000;
$verif_or+= $gbouclier*5000;
$verif_or+= $abouclier*8000;
$verif_or+= $pcoque*500;
$verif_or+= $gcoque*1000;
$verif_or+= $ccoque*2000;
$verif_or+= $ncoque*5000;
$verif_or+= $babel*3000000;

$verif_ada = $coutada;
$verif_ada+= $mitraillette_simple*10;
$verif_ada+= $mitraillette_ameliorer*15;
$verif_ada+= $pclaser*50;
$verif_ada+= $gclaser*60;
$verif_ada+= $pcions*100;
$verif_ada+= $gcions*110;
$verif_ada+= $plplasma*200;
$verif_ada+= $bplasma*180;
$verif_ada+= $glplasma*600;
$verif_ada+= $bnaquadria*2500;
$verif_ada+= $cnaquadria*5000;
$verif_ada+= $gcombustion*180;
$verif_ada+= $pimpulsion*200;
$verif_ada+= $gimpulsion*250;
$verif_ada+= $phyperspatial*300;
$verif_ada+= $ghyperspatial*350;
$verif_ada+= $gbouclier*700;
$verif_ada+= $abouclier*2000;
$verif_ada+= $ccoque*300;
$verif_ada+= $ncoque*400;


$verif_ura = $coutura;
$verif_ura+= $bnaquadria*400;
$verif_ura+= $cnaquadria*1000;
$verif_ura+= $gcombustion*200;
$verif_ura+= $ncoque*500;
$verif_ura+= $babel*1000000;

$verif_arme = 0;
$verif_arme+= $mitraillette_simple*1;
$verif_arme+= $mitraillette_ameliorer*2;
$verif_arme+= $pclaser*10;
$verif_arme+= $gclaser*16;
$verif_arme+= $pcions*22;
$verif_arme+= $gcions*30;
$verif_arme+= $plplasma*50;
$verif_arme+= $bplasma*70;
$verif_arme+= $glplasma*120;
$verif_arme+= $bnaquadria*250;
$verif_arme+= $cnaquadria*600;
//$verif_arme+= $babel*2000;

$verif_coque = 0;
$verif_coque+= $pcoque*40;
$verif_coque+= $gcoque*90;
$verif_coque+= $ccoque*200;
$verif_coque+= $ncoque*500;

$verif_bouclier = 0;
$verif_bouclier+= $mbouclier*40;
$verif_bouclier+= $champs*85;
$verif_bouclier+= $gbouclier*150;
$verif_bouclier+= $abouclier*400;

$verif_vitesse = 0;
$verif_vitesse+= $pcombustion*(1/20);
$verif_vitesse+= $gcombustion*(4/20);
$verif_vitesse+= $pimpulsion*(5/20);
$verif_vitesse+= $gimpulsion*(6/20);
$verif_vitesse+= $phyperspatial*(8/20);
$verif_vitesse+= $ghyperspatial*(10/20);
$verif_vitesse-= $babel*(4/20);

$verif_place = $place_base;
$verif_place-= $mitraillette_simple*1;
$verif_place-= $mitraillette_ameliorer*2;
$verif_place-= $pclaser*10;
$verif_place-= $gclaser*18;
$verif_place-= $pcions*25;
$verif_place-= $gcions*32;
$verif_place-= $plplasma*50;
$verif_place-= $bplasma*50;
$verif_place-= $glplasma*90;
$verif_place-= $bnaquadria*50;
$verif_place-= $cnaquadria*100;
$verif_place-= $pcombustion*5;
$verif_place-= $gcombustion*10;
$verif_place-= $pimpulsion*15;
$verif_place-= $gimpulsion*20;
$verif_place-= $phyperspatial*50;
$verif_place-= $ghyperspatial*100;
$verif_place-= $mbouclier*15;
$verif_place-= $champs*20;
$verif_place-= $gbouclier*30;
$verif_place-= $abouclier*50;
$verif_place-= $pcoque*5;
$verif_place-= $gcoque*15;
$verif_place-= $ccoque*25;
$verif_place-= $ncoque*35;
$verif_place-= $babel*5000;

if ($verif_bouclier == "") {
$verif_bouclier=0; }
if($nom=="" || $description=="") {

	echo '<script language=javascript> alert ("Un nom et une description sont obligatoire");</script>';

	include('creer.php');

	exit;

}
if($verif_place < 0) {

	echo '<script language=javascript> alert ("Votre vaisseau est en surcharge, veuillez libéré de la place");</script>';

	include('creer.php');

	exit;

}
if($verif_vitesse <= 0) {

	echo '<script language=javascript> alert ("Votre vaisseau n\'a pas assez de réacteurs pour décoller");</script>';

	include('creer.php');

	exit;

}
if($verif_vitesse > 4) {

	echo '<script language=javascript> alert ("Votre vaisseau a trop de réacteurs");</script>';

	include('creer.php');

	exit;

}
if($verif_coque <= 0) {

	echo '<script language=javascript> alert ("Votre vaisseau n\'a pas de coque, il ne pourra donc pas voler");</script>';

	include('creer.php');

	exit;

}
if($verif_arme <= 0) {

	echo '<script language=javascript> alert ("Votre vaisseau n\'a pas d\'arme,  hors tout les vaisseaux doivent posséder ou moins une arme en cas d\'attaque");</script>';

	include('creer.php');

	exit;

}

if($verif_bouclier < 0) {

	echo '<script language=javascript> alert ("Données incorrectes.");</script>';

	include('creer.php');

	exit;

}

$sql = "INSERT INTO matgraph_vaisseaux VALUES ('','0','$chantier_lvl','$idlogin','".addslashes($nom)."','".addslashes($description)."','$img','$mitraillette_simple','$mitraillette_ameliorer','$pclaser','$gclaser','$pcions','$gcions','$plplasma','$bplasma','$glplasma','$bnaquadria','$cnaquadria','$babel','$pcombustion','$gcombustion','$pimpulsion','$gimpulsion','$phyperspatial','$ghyperspatial','$mbouclier','$champs','$gbouclier','$abouclier','$pcoque','$gcoque','$ccoque','$ncoque','$verif_fer','$verif_or','$verif_ada','$verif_ura','$verif_place','$verif_vitesse','$verif_coque','$verif_bouclier','$verif_arme')";
$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());

$sql2 = "SELECT id FROM matgraph_vaisseaux WHERE nom='".addslashes($nom)."' AND fer='$fer'";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

$req = "SELECT id FROM matgraph_users WHERE idjoueur = $idlogin ORDER by id ASC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  While ( $row = mysql_fetch_array($res) ) {

$sql3 = "INSERT INTO matgraph_nbrevaisseaux VALUES ('','$idlogin','$row[id]','$row2[id]','0')";
$res3 = mysql_query($sql3)or die('erreur sql<br>'.$sql3.'<br>'.mysql_error());

}}

echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("chantier.php");
-->
</script>';
?>