Intanto il codice ripetuto potresti metterlo così (ho aggiuto il numero progressivo al nome del campo):
per il resto, quando fai il controllo potresti fare così:Codice PHP:
<?php
for($p=1; $p <= ($num_gioc) ; $p++ )
{
?>
<td bgcolor = "#FFFFFF" width = "50%">Nome giocatore</ td>
<td bgcolor = "#FFFFFF" width = "50%">
<input type = "text" name = "nome<?=$p; ?>">
</td>
</br>
<?php
}
?>
Codice PHP:
<?php
session_start();
ob_start();
?>
<html>
<head>
<title>Fantacalcio</title>
</head>
<body>
<h1 align="center">Inserimento giocatori della rosa</h1>
<?php
if( (isset($_SESSION['username']) &&
$_SESSION['username'] != "") ||
(isset($_SESSION['password']) &&
$_SESSION['password'] != ""))
{
//Connessione a MySql.
include $_SERVER['localhost'].'/includes/connect_Mysql.inc.php';
//Selezione del DB.
include $_SERVER['localhost'].'/includes/connect_DB.inc.php';
$num_gioc = $_SESSION['num_gioc'];
if( isset($_POST['submit']) && $_POST['submit'] == "Prosegui")
{
//qui vorrei controllare che tutti i nomi sono stati inseriti.
$err=0;
for($n=0; $n<30; $n++)
{
if(isset($_POST['nome'.$n]))
{
if(trim($_POST['nome'.$n]) == '') { $err++; }
} else { break; }
}
if($err==0)
{
//vai alla pagina successiva
}
else
{
//restituisci l'errore
}
}
else
{
?>
<form action="insert_player.php" method="post">
<?php
for($p=1; $p <= ($num_gioc) ; $p++ )
{
?>
<td bgcolor = "#FFFFFF" width = "50%">Nome giocatore</ td>
<td bgcolor = "#FFFFFF" width = "50%">
<input type = "text" name = "nome">
</td>
</br>
<?php
}
?>