Mammouth du PHP |
619 Messages
27 avr. 2013, 17:25
Bonjour,
voila une
DEMO en ligne
mes pages
add.php
<?php
include('config.php');
if (isset($_POST['pseudo']) && !empty($_POST['pseudo']) && isset($_POST['commentaire']) && !empty($_POST['commentaire'])){
$db = mysql_connect($host,$login,$pass);
mysql_select_db($base,$db);
$date = date("d-m-Y");
$pseudo=$_POST['pseudo'];
$commentaire=$_POST['commentaire'];
$email=$_POST['mail'];
$query = "INSERT INTO comment set pseudo='$pseudo',`mail`='$email',commentaire='$commentaire',`date`='$date'";
$req = mysql_query($query) or die('Erreur SQL !<br>'.$query.'<br>'.mysql_error());
mysql_close();
}
else{
echo '<span style="font: normal 12px Verdana;">Attention, seul le champ e-mail peut rester vide !</span>';
}
echo '<meta http-equiv="Refresh" content="0; URL=comment.php">';
?>
comment.php
. <? include('config.php'); ?>
<html>
<head>
<title>Commentaire</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="220" border="1" cellpadding="0" cellspacing="1" bordercolordark="#0066FF">
<!--DWLayoutTable-->
<tr>
<td width="356" height="287" valign="top"><div align="center">
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif">:: Commentaire ::</font></p>
<p><font color="#0066FF">——————————————————————</font>
<?
$db = mysql_connect($host,$login,$pass);
mysql_select_db($base,$db);
$req = mysql_query("SELECT * FROM comment");
$res = mysql_numrows($req);
echo "<font face=verdana size=1>Il y a actuellement <b>$res</b> commentaire</font>";
mysql_close();
?>
</p>
<p><br>
<?
$db = mysql_connect($host,$login,$pass);
mysql_select_db($base,$db);
$req = mysql_query("SELECT * FROM comment ORDER BY id DESC");
$res = mysql_numrows($req);
$i=0;
WHILE($res!=$i)
{
$pseudo = mysql_result($req,$i,"pseudo");
$date = mysql_result($req,$i,"date");
$commentaire = mysql_result($req,$i,"commentaire");
$mail = mysql_result($req,$i,"mail");
if($mail=='')
{
print"<p align=left><font face=verdana size=1>Le <b>$date</b> par <b>$pseudo</b><br><br><i>$commentaire</i></font></p>";
}
else
{
print"<p align=left><font face=verdana size=1>Le <b>$date</b> par <a href=mailto:$mail><b>$pseudo</b></a><br><br><i>$commentaire</i></font></p>";
}
$i++;
}
mysql_close();
?>
</p>
<p><font color="#0066FF">——————————————————————</font></p>
<form method="post" action="add.php">
<table width="356" border="0" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="126" height="22" valign="top"><font size="1" face="Verdana"><u>Votre
pseudo :</u></font></td>
<td colspan="2" valign="top"> <input type="text" class=text name="pseudo">
</td>
<td width="2"> </td>
<td width="19"> </td>
</tr>
<tr>
<td height="23" colspan="2" valign="top"><font size="1" face="Verdana"><u><em>Votre
e-mail :</em></u></font></td>
<td colspan="2" valign="top"> <input type="text" class=text name="mail">
</td>
<td> </td>
</tr>
<tr>
<td height="70" colspan="2" valign="top"><font size="1" face="Verdana"><u>Commentaire
:</u></font></td>
<td colspan="2" valign="top"> <textarea name="commentaire" cols="18" rows="3" id="commentaire"></textarea>
</td>
<td> </td>
</tr>
<tr>
<td height="24" colspan="5" valign="top"> <div align="center">
<input type="submit" class=bouton name="Submit" value="Ok">
</div></td>
</tr>
<tr>
<td height="19"> </td>
<td width="1"> </td>
<td width="208"> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</div></td>
</tr>
</table>
</body>
</html>
config.php
<?php
$host='localhost';
$login='test';
$pass='test';
$base='test';
?>