par
Overcride » 05 nov. 2011, 17:04
Bonjour,
J'essaie de créer un script qui gère les admins d'un serveur de jeu. Je voudrais que grace à un formulaire je puisse stocker dans une base de donnée, le speudo du joueur et quelques autres données mais aussi faire un genre de compte à rebours pour me rappeler dans combien de temps il ne sera plus admin. Hors tous ce passe bien sauf le compte à rebours que je ne sais absolument pas faire et après quelque recherche je n'ai pas compris. Ou alors ca ne me dérange pas de mettre juste la date d'expiration mais la aussi ca coince car après que j'utilise DATE_ADD je en sais pas utiliser DATE_FORMAT ... pour mettre au format JJ/MM/AAAA.
Les dates dans ma base de donnée ont l’attribut DATE.
Je m'excuse si je suis pas assez précis n’hésitai pas à me demander plus d'info.
J'ai 3 page :
Index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>
<body>
<table>
<caption>Liste des admins</caption>
<tr>
<th>Speudo</th>
<th>Steam amis</th>
<th>Steam_ID</th>
<th>Date de début</th>
<th>Date de fin</th>
</tr>
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=???;dbname=???', '????', '???', $pdo_options);
$req = $bdd->query('SELECT id, speudo, steam_amis, steam_ID, DATE_FORMAT(date_debut, \'%d/%m/%Y\') AS date_fr, DATE_ADD(date_fin, INTERVAL 1 MONTH) AS date_expiration FROM formulaire_admin ORDER BY id DESC');
while ($donnees = $req->fetch())
{
?>
<tr>
<td><?php echo htmlspecialchars($donnees['speudo']); ?></td>
<td><?php echo htmlspecialchars($donnees['steam_amis']); ?></td>
<td><?php echo htmlspecialchars($donnees['steam_ID']); ?></td>
<td><?php echo htmlspecialchars($donnees['date_fr']); ?></td>
<td>Il reste <?php echo htmlspecialchars($donnees['???']); ?>jour(s) avant expiration</td>
</tr>
<?php
}
$req->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
</table>
<br/>
<br/>
Pour mettre un nouveau admin cliquer <a href="admin/formulaire.php">ici</a>.
</body>
</html>
Formulaire.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>exemple</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>
<body>
<?php
if (!isset($_POST['mot_de_passe']) OR $_POST['mot_de_passe'] != "???")
{
?>
Veuillez entrer le mot de passe
<form action="formulaire.php" method="post">
<input type="password" name="mot_de_passe" />
<input type="submit" value="Valider" />
</form>
<?php
}
else
{
?>
<p>
<h2>test</h2>
<form action="formulaire_post.php" method="post">
<table>
<tr>
<td><label for="speudo">Speudo</label> :</td>
<td><input type="text" name="speudo" id="speudo" /></td>
</tr>
<tr>
<td><label for="steam_amis">Steam_amis</label> :</td>
<td><input type="text" name="steam_amis" id="steam_amis" /></td>
</tr>
<tr>
<td><label for="steam_ID">Steam_ID</label> :</td>
<td><input type="text" name="steam_ID" id="steam_ID" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Envoyer" /></td>
</tr>
</table>
</form>
</p>
<?php
}
?>
</body>
</html>
Formulaire_post.php
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=???;dbname=???', '????', '???', $pdo_options);
$req = $bdd->prepare('INSERT INTO formulaire_admin (speudo, steam_amis, steam_ID, date_debut, date_fin) VALUES(?, ?, ?, CURDATE(), CURDATE())');
$req->execute(array($_POST['speudo'], $_POST['steam_amis'], $_POST['steam_ID'], ));
header('Location: ../index.php');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
Vous pouvez voir le résultat sur
http://www.overcride.fr/exemple/script_php_liste_admin
Bonjour,
J'essaie de créer un script qui gère les admins d'un serveur de jeu. Je voudrais que grace à un formulaire je puisse stocker dans une base de donnée, le speudo du joueur et quelques autres données mais aussi faire un genre de compte à rebours pour me rappeler dans combien de temps il ne sera plus admin. Hors tous ce passe bien sauf le compte à rebours que je ne sais absolument pas faire et après quelque recherche je n'ai pas compris. Ou alors ca ne me dérange pas de mettre juste la date d'expiration mais la aussi ca coince car après que j'utilise DATE_ADD je en sais pas utiliser DATE_FORMAT ... pour mettre au format JJ/MM/AAAA.
Les dates dans ma base de donnée ont l’attribut DATE.
Je m'excuse si je suis pas assez précis n’hésitai pas à me demander plus d'info.
J'ai 3 page :
Index.php
[php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>
<body>
<table>
<caption>Liste des admins</caption>
<tr>
<th>Speudo</th>
<th>Steam amis</th>
<th>Steam_ID</th>
<th>Date de début</th>
<th>Date de fin</th>
</tr>
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=???;dbname=???', '????', '???', $pdo_options);
$req = $bdd->query('SELECT id, speudo, steam_amis, steam_ID, DATE_FORMAT(date_debut, \'%d/%m/%Y\') AS date_fr, DATE_ADD(date_fin, INTERVAL 1 MONTH) AS date_expiration FROM formulaire_admin ORDER BY id DESC');
while ($donnees = $req->fetch())
{
?>
<tr>
<td><?php echo htmlspecialchars($donnees['speudo']); ?></td>
<td><?php echo htmlspecialchars($donnees['steam_amis']); ?></td>
<td><?php echo htmlspecialchars($donnees['steam_ID']); ?></td>
<td><?php echo htmlspecialchars($donnees['date_fr']); ?></td>
<td>Il reste <?php echo htmlspecialchars($donnees['???']); ?>jour(s) avant expiration</td>
</tr>
<?php
}
$req->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
</table>
<br/>
<br/>
Pour mettre un nouveau admin cliquer <a href="admin/formulaire.php">ici</a>.
</body>
</html>[/php]
Formulaire.php
[php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>exemple</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>
<body>
<?php
if (!isset($_POST['mot_de_passe']) OR $_POST['mot_de_passe'] != "???")
{
?>
Veuillez entrer le mot de passe
<form action="formulaire.php" method="post">
<input type="password" name="mot_de_passe" />
<input type="submit" value="Valider" />
</form>
<?php
}
else
{
?>
<p>
<h2>test</h2>
<form action="formulaire_post.php" method="post">
<table>
<tr>
<td><label for="speudo">Speudo</label> :</td>
<td><input type="text" name="speudo" id="speudo" /></td>
</tr>
<tr>
<td><label for="steam_amis">Steam_amis</label> :</td>
<td><input type="text" name="steam_amis" id="steam_amis" /></td>
</tr>
<tr>
<td><label for="steam_ID">Steam_ID</label> :</td>
<td><input type="text" name="steam_ID" id="steam_ID" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Envoyer" /></td>
</tr>
</table>
</form>
</p>
<?php
}
?>
</body>
</html>[/php]
Formulaire_post.php
[php]<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=???;dbname=???', '????', '???', $pdo_options);
$req = $bdd->prepare('INSERT INTO formulaire_admin (speudo, steam_amis, steam_ID, date_debut, date_fin) VALUES(?, ?, ?, CURDATE(), CURDATE())');
$req->execute(array($_POST['speudo'], $_POST['steam_amis'], $_POST['steam_ID'], ));
header('Location: ../index.php');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>[/php]
Vous pouvez voir le résultat sur [url]http://www.overcride.fr/exemple/script_php_liste_admin[/url]