par
nico44530 » 21 juin 2012, 20:08
Tu pourrais m'expliquer ou tu met la condition dans la page "bloc-center.php" ci-dessous :
Code : Tout sélectionner
if( empty($titre) || empty($news)) {
[ Script d'envoi du formulaire ]
} else {
echo 'Erreur';
}
Et comment fait-on pour ne pas envoyer le formulaire si le champ "Article" contient l'expression : "Exprimez-vous..." ?
Page bloc-center.php :
<?php echo $reponse; ?>
<?php if(isset($_COOKIE["pseudo"])) { ?>
<?php
$db_link = mysql_connect("...", "...", "...");
mysql_select_db("...", $db_link);
if(isset($_POST)) {
foreach($_POST as $k => $v) {
$_POST[$k] = trim(htmlspecialchars($v)) ;
}
}
if(isset($_GET)) {
foreach($_GET as $k => $v) {
$_GET[$k] = trim(htmlspecialchars($v)) ;
}
}
if(isset($_POST['send'])) {
if($_POST['send'] == 'new') {
$sql = "INSERT INTO wa_news (auteur,date,titre,news) values ('".$_COOKIE['pseudo_prenom']." ".$_COOKIE['pseudo_nom']."',now(),'".$_POST['titre']."','".$_POST['news']."')";
}
elseif($_POST['send'] == 'update') {
$sql = 'update wa_news set titre = "'.$_POST['titre'].'", auteur =
"'.$_COOKIE['pseudo_prenom'].' '.$_COOKIE['pseudo_nom'].'", news = "'.$_POST['news'].'", date =
"'.$_POST['date'].'" WHERE newsId = "'.$_POST['newsId'].'"';
}
mysql_query($sql,$db_link) or die(mysql_error());
}
if(isset($_GET['delete']) and is_numeric($_GET['delete'])) {
mysql_query("delete from wa_news where newsId = \"".$_GET['delete']."\"",$db_link);
}
if(isset($_GET['edit']) and is_numeric($_GET['edit'])) {
$Id = $_GET['edit'] ;
$sql = 'SELECT * FROM wa_news WHERE newsId="'.$Id.'" LIMIT 1' ;
$rc = mysql_query($sql,$db_link);
while($data = mysql_fetch_array($rc)) { ?>
<div class="bloc_03">
<h1 class="separate">Modifier l'article</h1>
<form action="home.php" method="post">
<table>
<tr><td class="titre-news">Titre :</td></tr>
<tr><td><input type="text" class="news-titre" name="titre" value="<?php echo htmlentities($data['titre']); ?>" /></td></tr>
<tr><td class="titre-news">Article :</td></tr>
<tr><td><textarea name="news" class="news-article"><?php echo htmlentities($data['news']); ?></textarea></td></tr>
</table>
<input type="hidden" name="newsId" value="<?php echo $_GET['edit']; ?>" />
<input type="hidden" name="send" value="update" />
<input type="submit" src="" class="submit-news" value="" />
</form>
</div>
<?php }
}
else { ?>
<div class="bloc_03">
<h1 class="separate">Poster un article</h1>
<form action="home.php" method="post">
<table>
<tr><td class="titre-news">Titre :</td></tr>
<tr><td><input type="text" autocomplete="off" class="news-titre" name="titre" /></td></tr>
<tr><td class="titre-news">Article :</td></tr>
<tr><td><textarea name="news" autocomplete="off" class="news-article" value="Exprimez-vous..." onfocus="if (this.value==this.defaultValue) this.value = ''" onblur="if (this.value=='') this.value = this.defaultValue">Exprimez-vous...</textarea></td></tr>
</table>
<input type="hidden" name="send" value="new" />
<input type="submit" src="" class="submit-news" value="" />
</form>
</div>
<?php
$sql = 'SELECT * FROM wa_news ORDER BY newsId DESC' ;
$rc = mysql_query($sql,$db_link);
while($data = mysql_fetch_array($rc)) {
$data['date'] = date('d/m/Y');
?>
<div class="bloc_03">
<h1 class="separate"><?php echo $data['titre']; ?></h1>
Le <?php echo $data['date']; ?> par <?php echo $data['auteur']; ?><br />
<?php echo $data['news']; ?>
<br />=> <a href="?delete=<?php echo $data['newsId']; ?>">Supprimer</a> -
<a href="?edit=<?php echo $data['newsId']; ?>">Editer</a>
</div>
<?php }
}
mysql_close();
?>
<?php } else { ?>
<div class="bloc_03">
<h1 class="separate">Actualités à la Une</h1>
</div>
<?php } ?>
Tu pourrais m'expliquer ou tu met la condition dans la page "bloc-center.php" ci-dessous :
[code]if( empty($titre) || empty($news)) {
[ Script d'envoi du formulaire ]
} else {
echo 'Erreur';
}[/code]
Et comment fait-on pour ne pas envoyer le formulaire si le champ "Article" contient l'expression : "Exprimez-vous..." ?
Page bloc-center.php :
[php]
<?php echo $reponse; ?>
<?php if(isset($_COOKIE["pseudo"])) { ?>
<?php
$db_link = mysql_connect("...", "...", "...");
mysql_select_db("...", $db_link);
if(isset($_POST)) {
foreach($_POST as $k => $v) {
$_POST[$k] = trim(htmlspecialchars($v)) ;
}
}
if(isset($_GET)) {
foreach($_GET as $k => $v) {
$_GET[$k] = trim(htmlspecialchars($v)) ;
}
}
if(isset($_POST['send'])) {
if($_POST['send'] == 'new') {
$sql = "INSERT INTO wa_news (auteur,date,titre,news) values ('".$_COOKIE['pseudo_prenom']." ".$_COOKIE['pseudo_nom']."',now(),'".$_POST['titre']."','".$_POST['news']."')";
}
elseif($_POST['send'] == 'update') {
$sql = 'update wa_news set titre = "'.$_POST['titre'].'", auteur =
"'.$_COOKIE['pseudo_prenom'].' '.$_COOKIE['pseudo_nom'].'", news = "'.$_POST['news'].'", date =
"'.$_POST['date'].'" WHERE newsId = "'.$_POST['newsId'].'"';
}
mysql_query($sql,$db_link) or die(mysql_error());
}
if(isset($_GET['delete']) and is_numeric($_GET['delete'])) {
mysql_query("delete from wa_news where newsId = \"".$_GET['delete']."\"",$db_link);
}
if(isset($_GET['edit']) and is_numeric($_GET['edit'])) {
$Id = $_GET['edit'] ;
$sql = 'SELECT * FROM wa_news WHERE newsId="'.$Id.'" LIMIT 1' ;
$rc = mysql_query($sql,$db_link);
while($data = mysql_fetch_array($rc)) { ?>
<div class="bloc_03">
<h1 class="separate">Modifier l'article</h1>
<form action="home.php" method="post">
<table>
<tr><td class="titre-news">Titre :</td></tr>
<tr><td><input type="text" class="news-titre" name="titre" value="<?php echo htmlentities($data['titre']); ?>" /></td></tr>
<tr><td class="titre-news">Article :</td></tr>
<tr><td><textarea name="news" class="news-article"><?php echo htmlentities($data['news']); ?></textarea></td></tr>
</table>
<input type="hidden" name="newsId" value="<?php echo $_GET['edit']; ?>" />
<input type="hidden" name="send" value="update" />
<input type="submit" src="" class="submit-news" value="" />
</form>
</div>
<?php }
}
else { ?>
<div class="bloc_03">
<h1 class="separate">Poster un article</h1>
<form action="home.php" method="post">
<table>
<tr><td class="titre-news">Titre :</td></tr>
<tr><td><input type="text" autocomplete="off" class="news-titre" name="titre" /></td></tr>
<tr><td class="titre-news">Article :</td></tr>
<tr><td><textarea name="news" autocomplete="off" class="news-article" value="Exprimez-vous..." onfocus="if (this.value==this.defaultValue) this.value = ''" onblur="if (this.value=='') this.value = this.defaultValue">Exprimez-vous...</textarea></td></tr>
</table>
<input type="hidden" name="send" value="new" />
<input type="submit" src="" class="submit-news" value="" />
</form>
</div>
<?php
$sql = 'SELECT * FROM wa_news ORDER BY newsId DESC' ;
$rc = mysql_query($sql,$db_link);
while($data = mysql_fetch_array($rc)) {
$data['date'] = date('d/m/Y');
?>
<div class="bloc_03">
<h1 class="separate"><?php echo $data['titre']; ?></h1>
Le <?php echo $data['date']; ?> par <?php echo $data['auteur']; ?><br />
<?php echo $data['news']; ?>
<br />=> <a href="?delete=<?php echo $data['newsId']; ?>">Supprimer</a> -
<a href="?edit=<?php echo $data['newsId']; ?>">Editer</a>
</div>
<?php }
}
mysql_close();
?>
<?php } else { ?>
<div class="bloc_03">
<h1 class="separate">Actualités à la Une</h1>
</div>
<?php } ?>
[/php]