Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD
PHP & SGBD Forum d'entraide sur les SGBD avec PHP. Avant de poster : FAQ BDD, toutes les FAQ PHP, cours BDD et sources BDD
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 10/06/2006, 16h46   #1
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
Par défaut [SQL] Editeur de news

Bonjour,
je suis en train de réaliser un site entièrement en php avec une partie admin. Voici mon code :

page news.php
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
<html>
<head>
<title>Document sans titre</title>
 
</head>
 
<body>
<h1>Derniers articles du site</h1>
<?PHP
mysql_connect("localhost", "root", "");
mysql_select_db("paroisse");
$retour = mysql_query('SELECT * FROM news ORDER BY DESC LIMIT 0, 5');
while ($donnees = mysql_fetch_array($retour))
{
?>
<div class="news">
	<h3>
	<?php echo $donnees['titre']; ?>
	<em>le<?php echo date('d/m,Y à H/hi', $donnees['timestamp']); ?></em>
	</h3>
 
	<p>
	<?php 
	$contenu = nl2br (stripslashes($donnees['contenu']));
	echo $contenu;
	?>
	</p>
	</div>
	<?php
	}
	?>
</body>
</html>

page list_news.php
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
<html>
<head>
<title></title>
 
</head>
 
<body>
<h2><a href="rediger_news.php"> Ajouter une news </a></h2>
<?php 
mysql_connect ("localhost", "root", "");
mysql_select_db("paroisse");
 
// Vérification des news (veut-on poster ?)
 
if (isset($_POST['titre']) AND iset($_POST['contenu']))
{
$titre = addslashes($_POST['titre']);
$contenu = addslashes($_POST['contenu']);
if ($_POST['id_news']==0)
{
mysql_query("INSERT INTO news VALUES(","'.$titre.'","'.contenu."','".time().'"));
}
else
{
mysql_query("UPDATE news SET titre"'.$titre.'".contenu="'.$contenu.'"WHERE id=".$_POST['id_news']);
 
// Est-ce que lon veut supprimer une news ?
 
if (isset($_GET['suprimer_news']))
{
mysql_query('DELETE FROM news WHERE id='.$_GET['supprimer_news']);
}
?>
 
<table><tr>
<th>Modifier</th>
<th>Supprimer</th>
<th>Titre</th>
<th>Date</th>
</tr>
 
<?php
$retour = mysql_query('SELECT * FROM nws ORDER BY id DESC');
while ($donnees = mysql_fetch_array ($retour))
{
?>
 
<tr>
<td><?php echo '<a href="rediger_news.php?modifier_news='.$donnees['id'].'">'; ?> Modifier</td>
<td><?php echo '<a href="liste_news.php?supprimer_news='.$donnees['id'].'">'; ?> Supprimer</td>
<td><?php echo stripslashes($donnees['titre']); ?></td>
<td><?php echo date('d/m/Y', $donnees['timestamp']); ?></td>
</tr>
 
<?php
}
?>
</table>
</body>
</html>
page rediger_news.php
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
<html>
<head>
<title></title>
 
</head>
 
<body>
<h3><a href="liste_news.php"> Retour à la liste des news</a></h3>
<?php
mysql_connect ("localhost", "root", "");
mysql_select_db("paroisse");
 
if (isset($_GET['modifier_news']))
{
$retour = mysql_query('SELECT * FROm news WHERE id='.$_GET['modifier_news']);
$donnees = mysql_fetch_array($retour);
 
$titre = $donnees['titre'];
$contenu = $donnees['contenu'];
$id_news = $donnees['id'];
}
else
{
$titre='';
$contenu='';
$id_news = 0;
?>
 
<div align="center">
  <form name="form1" method="post" action="liste_news.php">
    <p>Titre : 
      <input type="text" name="titre" value="<?php echo $titre; ?>">
</p>
    <p>Contenu<br>
      <textarea name="contenu" cols="80" rows="12" wrap="VIRTUAL">
	  <?php echo $contenu ?>
	  </textarea> 
    </p>
    <p>
	<input type="hidden" name = "id_news" value="<?php echo $id_news; ?>">
      <input type="submit" name="Submit" value="Envoyer">  
      </p>
  </form>
</div>
</body>
 
</html>
Le problème c'est que rien ne marche.
A votre avis, d'où vient le problème ?

je travaille sur ce code depuis plusieurs jours et reste bloqué sur ce point. Tout le reste fonctionne (includes, menus ...).

merci de votre aide
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 17h04   #2
Membre chevronné
 
Avatar de kankrelune
 
Inscription : décembre 2005
Messages : 766
Détails du profil
Informations forums :
Inscription : décembre 2005
Messages : 766
Points : 745
Points : 745
Citation:
Envoyé par guiguistuder
Le problème c'est que rien ne marche.
C'est à dire... des messages d'erreurs... .. ?

@ tchaOo°
kankrelune est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 17h07   #3
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
Quand je regarde rediger _news.php :

Parse error: parse error, unexpected $ in rediger_news.php on line 49

et list_news :
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in liste_news.php on line 22

J'ai essayé plusieurs variantes mais ces erreurs reviennent la plupart du temps.
merci

Et pour news.php :

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in news.php on line 10

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in news.php on line 11

Warning: mysql_select_db(): A link to the server could not be established in news.php on line 11

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in news.php on line 12

Warning: mysql_query(): A link to the server could not be established in news.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in news.php on line 13
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 18h17   #4
Inactif
 
Avatar de Kerod
 
Inscription : septembre 2004
Messages : 11 753
Détails du profil
Informations forums :
Inscription : septembre 2004
Messages : 11 753
Points : 14 585
Points : 14 585
Ce sont des parse error tu pourrais trouver quand même tes propres fautes de syntaxe

Code :
1
2
3
4
5
else
{
$titre='';
$contenu='';
$id_news = 0;
manque le }

pour cette page je crois que c'est la seule.
Et l'autre page ce sont des warnings et non des erreurs
Kerod est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 18h23   #5
Membre chevronné
 
Avatar de kankrelune
 
Inscription : décembre 2005
Messages : 766
Détails du profil
Informations forums :
Inscription : décembre 2005
Messages : 766
Points : 745
Points : 745
Citation:
Envoyé par guiguistuder
Parse error: parse error, unexpected $ in rediger_news.php on line 49
Ton else ne se finnit pas (manque l'accolade de fin)... .. .

Citation:
Envoyé par guiguistuder
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in liste_news.php on line 22
Code :
mysql_query("INSERT INTO news VALUES(","'.$titre.'","'.contenu."','".time().'"));
Tu te mélange les pinceaux entre simples et doubles quotes... il manque $ à contenu et tu as une fermeture de parenthèse en trop à la fin... .. .

Code :
iset($_POST['contenu'])
Ca serait pas plutot... isset... .. .

Citation:
Envoyé par guiguistuder
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in news.php on line 10

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in news.php on line 11

Warning: mysql_select_db(): A link to the server could not be established in news.php on line 11

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in news.php on line 12

Warning: mysql_query(): A link to the server could not be established in news.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in news.php on line 13
Inutile de traduire... .. .

Allez c'est noël avant l'heure... .. .

page db.php

Code :
1
2
3
4
5
6
7
 
<?php
 
mysql_connect("localhost", "root", "");
mysql_select_db("paroisse");
 
?>

page news.php

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
<html>
<head>
<title>Document sans titre</title>
</head>
<body>
<h1>Derniers articles du site</h1>
<?php
include('db.php');
 
if(isset($_POST['op']))
	$op = $_POST['op'];
		elseif(isset($_GET['op']))
			$op = $_GET['op'];
				else
					$op = 'main';
 
if($op == 'read')
{
	if(isset($_POST['id']))
		$id = strip_tags($_POST['id']);
			elseif(isset($_GET['id']))
				$id = strip_tags($_GET['id']);
 
	$retour = mysql_query('SELECT titre,contenu,id FROM news WHERE id='.$id);
	$donnees = mysql_fetch_array($retour);
	?>
		<div class="news">
			<h3>
				<?php echo $donnees['titre'].' <em>le '.date('d/m,Y à H/hi', $donnees['timestamp']); ?></em>
			</h3>
		<p>
		<?php echo nl2br(stripslashes($donnees['contenu'])); ?>
		</p>
		<p>
			<a href="?op=main">Retour</a>
		</p>
	</div>
	<?php
}
else
{
	$retour = mysql_query('SELECT id,titre,timestamp,contenu FROM news ORDER BY DESC LIMIT 0, 5');
	while ($donnees = mysql_fetch_array($retour))
	{
	?>
		<div class="news">
			<h3>
				<?php echo $donnees['titre'].' <em>le '.date('d/m,Y à H/hi', $donnees['timestamp']); ?></em>
			</h3>
		<p>
		<?php echo substr(nl2br(stripslashes($donnees['contenu'])),0,250).'...'; ?>
		</p>
		<p>
			<a href="?op=read&id=<?php echo $donnees['id']; ?>">Lire la suite...</a>
		</p>
	</div>
<?php
}
?>
</body>
</html>
page liste_news.php

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
<html>
<head>
<title></title>
</head>
<body>
<h2><a href="rediger_news.php"> Ajouter une news </a></h2>
<?php 
include('db.php');
 
if(isset($_POST['op']))
	$op = $_POST['op'];
		elseif(isset($_GET['op']))
			$op = $_GET['op'];
				else
					$op = 'main';
 
if(isset($_POST['id']))
	$id = strip_tags($_POST['id']);
		elseif(isset($_GET['id']))
			$id = strip_tags($_GET['id']);
 
if($op == 'delete')
{
	if($id != '')
	{
		if(mysql_query('DELETE FROM news WHERE id='.$id))
			echo '<table>
					<tr>
						<th>La news &agrave; &eacute;t&eacute; supprim&eacute;e avec succ&egrave;s... .. .<br /><br />
						<a href="?">retour</a></th>
					</tr>
				</table>';
		else
			echo '<table>
					<tr>
						<th>Echec de la suppression de la news... .. .<br /><br />
						<a href="javascript:window.history.back();">retour</a></th>
					</tr>
				</table>';
	}
	else
		echo '<table>
				<tr>
					<th>Veuillez selectionner une news &agrave; supprimer... .. .<br /><br />
					<a href="javascript:window.history.back();">retour</a></th>
				</tr>
			</table>';
}
elseif($op == 'add' || $op == 'edit')
{
	if(!empty($_POST['titre']) && !empty($_POST['contenu']))
	{
		if (get_magic_quotes_gpc()) 
		{
			$titre = mysql_real_escape_string(stripslashes($_POST['titre']));
			$contenu = mysql_real_escape_string(stripslashes($_POST['contenu']));
		}
		else
		{
			$titre = mysql_real_escape_string($_POST['titre']);
			$contenu = mysql_real_escape_string($_POST['contenu']);
		}
 
		if (empty($_POST['id_news']))
		{
			$action = 'cr&eacute;ation';
			$result = mysql_query('INSERT INTO news VALUES(\'\',\''.$titre.'\',\''.$contenu.'\',\''.time().'\''));
		{
		else
		{
			$action = 'mise à jour';
			$result = mysql_query('UPDATE news SET titre=\''.$titre.'\',contenu=\''.$contenu.'\' WHERE id='.$_POST['id_news']);
		}
 
		if($result)
			echo '<table>
				<tr>
					<th>'.ucfirst($action).' effectu&eacute;e avec succ&egrave;s... .. .<br /><br />
					<a href="?">retour</a></th>
				</tr>
			</table>';
		else
			echo '<table>
					<tr>
						<th>Echec de la '.$action.' de la news... .. .<br /><br />
						<a href="javascript:window.history.back();">retour</a></th>
					</tr>
				</table>';
	}
	else echo '<table>
				<tr>
					<th>Veuillez entrer un titre et un contenu pour cr&eacute;er une nouvelle news... .. .<br /><br />
					<a href="javascript:window.history.back();">retour</a></th>
				</tr>
			</table>';
}
else
{
?>
<table>
	<tr>
		<th>Modifier</th>
		<th>Supprimer</th>
		<th>Titre</th>
		<th>Date</th>
	</tr>
<?php
	$retour = mysql_query('SELECT * FROM nws ORDER BY id DESC');
	while ($donnees = mysql_fetch_array ($retour))
	{
?>
	<tr>
		<td><a href="rediger_news.php?op=edit&id=<?php echo $donnees['id']; ?>">Modifier</td>
		<td><a href="?op=delete&id=<?php echo $donnees['id']; ?>">Supprimer</td>
		<td><?php echo stripslashes($donnees['titre']); ?></td>
		<td><?php echo date('d/m/Y', $donnees['timestamp']); ?></td>
	</tr>
<?php
	}
?>
</table>
<?php
}
?>
</body>
</html>
page rediger_news.php

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
<html>
<head>
<title></title>
</head>
<body>
<h3><a href="liste_news.php"> Retour à la liste des news</a></h3>
<?php
include('db.php');
 
if(isset($_POST['op']))
	$op = $_POST['op'];
		elseif(isset($_GET['op']))
			$op = $_GET['op'];
				else
					$op = 'main';
 
if(isset($_POST['id']))
	$id = strip_tags($_POST['id']);
		elseif(isset($_GET['id']))
			$id = strip_tags($_GET['id']);
 
if ($op == 'edit')
{
	$retour = mysql_query('SELECT titre,contenu,id FROM news WHERE id='.$id);
 
	if($retour)
	{
		$donnees = mysql_fetch_array($retour);
		$titre = $donnees['titre'];
		$contenu = $donnees['contenu'];
		$id_news = $donnees['id'];
	}
	else
	{
		$titre = '';
		$contenu = '';
		$id_news = '';
 
		echo '<table>
				<tr>
					<th>La news selection&eacute;e n\'existe pas... .. .<br /><br />
					<a href="javascript:window.history.back();">retour</a></th>
				</tr>
			</table>';
	}
}
else
{
	$titre = '';
	$contenu = '';
	$id_news = '';
}
?>
<div align="center">
  <form name="form1" method="post" action="liste_news.php?op=add">
	<input type="hidden" name = "id" value="<?php echo $id_news; ?>">
    <p>Titre : <input type="text" name="titre" value="<?php echo $titre; ?>"></p>
    <p>Contenu<br />
      <textarea name="contenu" cols="80" rows="12" wrap="VIRTUAL">
	  <?php echo $contenu ?>
	  </textarea> 
    </p>
    <p>
      <input type="submit" name="Submit" value="Envoyer">  
    </p>
  </form>
</div>
</body>
</html>
Voila... j'ais pas testé et il manque des trucs notament la gestion de certaines erreurs (par ex si une news n'existe pas dans la page news.php)... mais normalement ça devrait fonctionner... .. .

@ tchaOo°
kankrelune est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 14h35   #6
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
Par défaut éditeur de news suite

Bonjour à tous
j'ai suivi vosq conseils et j'ai refait entièrementle site. Mais il y a toujours des erreurs, surement d'inattention (je n'ai pas copié collé le code mais ai essayé de le comprendre !).
Voila le code de liste_news.php

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
 
 
<html>
<head>
<title></title>
 
</head>
 
<body>
<h2><a href="rediger_news.php"> Ajouter une news </a></h2>
<?php 
include('db.php');
 
if(isset($_POST['op']))
{
$op = $_POST['op'];
}
elseif (isset($_GET['op']))
{
$op=$_GET['op'];
}
else
{
$op='main';
}
if (isset($_POST['id']))
{
$id = strip_tags($_POST['id']);    
}
elseif (isset($_GET['id']))
{
$id = strip_tags($_GET['id']);
}
if ($op == 'delete')
{
	if($id != '')
	{
		if (mysql_query('DELETE FROM news WHERE id='.$id)) 
	{
	echo '<table>
			<tr> <th> La news a été supprmiée avec succès...
			.<br /><br />
			<a href="?"> retour</a></th>
			</tr>$id
		</table>';	
	}
	else
	{
	echo '<table> <tr> <th> Echec de la suppression de la news... .<br /><br />;
	<a href="javascript:windows.history.back()">retour</a></th></tr></table>';
	}
	}
	else
	{
	echo '<table><tr><th>Sélectionnez la nexs à supprimer... .<br /><br />
	<a href=javascript:window.history.back();">retour</></th></tr></table>';
	}
	}
	elseif($op == 'add' || $op == 'edit')
	{
	if(!empty($_POST['titre']) && !empty($_POST['contenu']))
	{
		if (get_magic_quotes_gpc())
		{
		$titre = mysql_real_escape_string(stripslashes($_POST['titre']));
		$contenu = mysql_real_escape_string(stripslashes($_POST['contenu']));    
		}
		else
		{
		$titre = mysql_real_escape_string($_POST['titre']);
		$contenu = mysql_real_escape_string($_POST['contenu']);
		}
		if (empty($_POST['id_news']))
		{
		$action = 'création';
		$result =  mysql_query('INSERT INTO news VALUES( \'\',\''.$titre.'\',\''.$contenu.'\', \''.time().'\'');  
		}
 
		else
		$action = 'mise à jour';
		$result = mysql_query('UPDATE news SET titre=\''.$titre.'\',contenu=\''.$contenu.'\' WHERE id'.$_POST['id_news']);
		{
 
 
		}
 
 
		if ($result) 
		{
		  echo '<table><tr><th>'.ucfirst($action).'effectuée avec succès<br /><br />
		  <a href="?">retour</a></th></tr></table>'; 
		}
		else
		{
			echo '<table><tr><th>Echec de la '.$action.'de la news<br /><br /> 
			<a href="javascript:windows.history.back();">retour</a></th></table>';
		}}
 
		else 
		{echo '<table><tr><th>Veuilez entrer un titre et un contenu pour créer uen nouvelle news...<br /><br />
		<a href="javascript:window.history.back()";>retour</a></th></tr></table>';
		}}
 
		else
		{
		?>
		<TABLE>
		<tr>
		<TH>Modifier</TH>
		<TH>supprimer</TH>
		<th>titre</th>
		<th>date</th>
		</tr>
 
	<?php
		$retour= mysql_query('SELECT * FROM news ORDER BY id desc');
		while($donnees = mysql_fetch_array($retour))
		{
		?>
		<tr><td><a href="rediger_news.php.op=edit&id=<?php echo $donnees['id']; ?>"</a>Modifier</td>
		<td><a href="?op=delete&id=<?php echo $donnees['id']; ?>">Supprimer</a></td>
		<td><?php echo stripslashes($donnees['titre']); ?></td>
		<td><?php echo date('d/m/Y', $donnees['timestamp']); ?> </td>
 
		</tr>	
		<?php
		}
		?>
		</TABLE>
		<?php
		}
		?>
 
</body>
</html>
Code de news.php :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
<html>
<head>
<title>Document sans titre</title>
 
</head>
 
<body>
<h1>Derniers articles du site</h1>
<?PHP
include('db.php');
 
if (isset($_POST['op']))
{
$op = $_POST['op'];
}
elseif (isset($GET['op']))
{
$op = $_GET['op'];
}
else
{
$op = 'main';    
}
 
if($op == 'read')
{
if (isset($_POST['id']))
{
   $id = strip_tags($_POST('id')); 
}
elseif (isset($_GET['id']))
{
$id = strip_tags($_Get['id']);
}
 
$retour = mysql_query('SELECT titre, contenu, id FROM news WHERE id'.$id);
$donnees = mysql_fetch_array($retour);
?>
 
<DIV class="news">
 
<h3> <?php echo $donnees['titre'].'<em>le'.date('d.m,Y à H/hi', $donnees['timestamp']); ?> </em></h3>
<p>
<?php echo n12br(stripslashes($donnees['contenu']))?> 
</p>
<p>
<A href="op=main">Retour</A>
</p>
</DIV>
<?php
}
else
{
$retour = mysql_query('SELECT id, titre, timestamp, contenu FROM news ORDER BY DESC Limit 0, 5');
while ($donnees = mysql_fetch_array($retour))
{
 ?>
<DIV class = "news">
<H3>
<?php echo $donnees['titre'].'<em>le'.date('d/m,Y à H,hi', $donnees['timestamp']); ?></em>
</H3>
<p>
<?php echo substr(n12br(stripslashes($donnees['contenu'])), 0, 250).'...'; ?>
</p>
<P>
<a href = "?op=read&id= <?php echo $donnees['id']; ?>"> Lire la suite</a>
</P>
</DIV>
<?php
}}
?>
</body>
</html>
Et code de rediger_news.php

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
 
<html>
<head>
<title></title>
 
</head>
 
<body>
<h3><a href="liste_news.php"> Retour à la liste des news</a></h3>
<?php
if (isset($_POST['op']))
 {
 $op = $_POST['op'];   
}
elseif (isset($_GET['op']))
{
$op = $_GET['op'];
}
else
{
$op= 'main';
}
 
if (isset($_POST['id']))
 {
  $id = strip_tags($_POST['id']);  
}
elseif (isset($_GET['id']))
{
$id = strip_tags($_GET['id']);
}
 
if ($op == 'edit')
{
 $retour = mysql_query('SELECT titre, contenu, id FROM news WHERE id'.$id);   
 
 
if ($retour)
 {
    $donnees = mysql_fetch_array($retour);
	$titre = $donnees['titre'];
	$contenu = $donnees['contenu'];
	$id_news = $donnees['id'];
}
else
{
$titre = '';
$contenu = '';
$id_news = '';
echo '<table><tr><th>La news sélectionee nexiste pas<br /><br />
<a href="javascript:window.history.back();">retour</a></th></tr></table>';
}}
else
{
$titre = '';
$contenu = '';
$id_news = '';
}
?>
 
<div align="center">
  <form name="form1" method="post" action="liste_news.php?op=add">
    <p>Titre : 
      <input type="text" name="titre" value="<?php echo $id_news; ?>">
</p>
    <p>Contenu<br>
      <textarea name="contenu" cols="80" rows="12" wrap="VIRTUAL">
	  <?php echo $contenu ?>
	  </textarea> 
    </p>
    <p>
	<input type="hidden" name = "id" value="<?php echo $id_news; ?>">
      <input type="submit" name="Submit" value="Envoyer">  
      </p>
  </form>
</div>
</body>
 
</html>

Voici les erreurs que je reçois :
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 14h37   #7
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
news.php :

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in news.php on line 55

liste_news.php :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in liste_news.php on line 116

mais rediger.php fonctionne mais quand je clique sur envoyer, apparait :
admin/liste_news.php?op=add
erreur lors de la création de la news.

merci de votre aide
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 15h10   #8
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
le problème est réglé. Le problème venait de ma base de donnée. Mais maintennat, quand je remplis une news, il est écrit "création effectuée avec succès, mais rien ne saffiche dans liste_news.php ???
doù vient le problème ?
merci
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 15h12   #9
Inactif
 
Avatar de Kerod
 
Inscription : septembre 2004
Messages : 11 753
Détails du profil
Informations forums :
Inscription : septembre 2004
Messages : 11 753
Points : 14 585
Points : 14 585
Je dirais avant tout corrige les erreurs de syntaxe :
new.php
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<html>
<head>
<title>Document sans titre</title>

</head>

<body>
<h1>Derniers articles du site</h1>
<?PHP
include('db.php');

if (isset($_POST['op']))
{
$op = $_POST['op'];
}
elseif (isset($GET['op']))
{
$op = $_GET['op'];
}
else
{
$op = 'main';    
}

if($op == 'read')
{
if (isset($_POST['id']))
{
   $id = strip_tags($_POST('id')); 
}
elseif (isset($_GET['id']))
{
$id = strip_tags($_Get['id']);
}

$retour = mysql_query('SELECT titre, contenu, id FROM news WHERE id'.$id);
$donnees = mysql_fetch_array($retour);
?>

<DIV class="news">

<h3> <?php echo $donnees['titre'].'<em>le'.date('d.m,Y à H/hi', $donnees['timestamp']); ?> </em></h3>
<p>
<?php echo n12br(stripslashes($donnees['contenu']))?> 
</p>
<p>
<A href="op=main">Retour</A>
</p>
</DIV>
<?php
}
else
{
$retour = mysql_query('SELECT id, titre, timestamp, contenu FROM news ORDER BY DESC Limit 0, 5');
while ($donnees = mysql_fetch_array($retour))
{
 ?>
<DIV class = "news">
<H3>
<?php echo $donnees['titre'].'<em>le'.date('d/m,Y à H,hi', $donnees['timestamp']); ?></em>
</H3>
<p>
<?php echo substr(n12br(stripslashes($donnees['contenu'])), 0, 250).'...'; ?>
</p>
<P>
<a href = "?op=read&id= <?php echo $donnees['id']; ?>"> Lire la suite</a>
</P>
</DIV>
<?php
}}
?>
</body>
</html>
Kerod est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 15h25   #10
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
C'est bon, c'est corrigé.
Et j'en ai trouvé d'autres au passage...
Mais le vrai problème c'ets que rien ne s'affiche dans liste_news.php quand j'écris un message sous rediger_news.php même si il est écrit 'message envoyé avec succès' ?
merci
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 16h38   #11
Inactif
 
Avatar de Kerod
 
Inscription : septembre 2004
Messages : 11 753
Détails du profil
Informations forums :
Inscription : septembre 2004
Messages : 11 753
Points : 14 585
Points : 14 585
J'ai modifié certaines choses sur la première page :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<h2><a href="rediger_news.php"> Ajouter une news </a></h2>
<?php 
include('db.php');
 
 
$op = isset($_POST['op'])?($_POST['op']):(isset($_GET['op'])?($_GET['op']):('main'));
 
if ( isset($_POST['id']) )
    $id = strip_tags($_POST['id']);    
elseif (isset($_GET['id']))
    $id = strip_tags($_GET['id']);
 
 
if ($op == 'delete')
{
    if($id != '')
    {
        if (mysql_query('DELETE FROM news WHERE id='.$id)) 
            echo '<table><tr><th>La news a été supprmiée avec succès....<br /><br /><a href="?">retour</a></th></tr>'.$id.'</table>';    
        else
            echo '<table><tr><th>Echec de la suppression de la news....<br /><br /><a href="javascript:windows.history.back()">retour</a></th></tr></table>';
    }
    else
    {
        echo '<table><tr><th>Sélectionnez la nexs à supprimer... .<br /><br /><a href=javascript:window.history.back();">retour</></th></tr></table>';
    }
}
elseif($op == 'add' || $op == 'edit')
{
    if(!empty($_POST['titre']) && !empty($_POST['contenu']))
    {
        if (get_magic_quotes_gpc())
        {
            $titre = mysql_real_escape_string(stripslashes($_POST['titre']));
            $contenu = mysql_real_escape_string(stripslashes($_POST['contenu']));    
        }
        else
        {
            $titre = mysql_real_escape_string($_POST['titre']);
            $contenu = mysql_real_escape_string($_POST['contenu']);
        }
 
        if (empty($_POST['id_news']))
        {
            $action = 'création';
            $result =  mysql_query("INSERT INTO news VALUES('','$titre','$contenu', 'time()'");  
        }
        else
        {
            $action = 'mise à jour';
            $result = mysql_query("UPDATE news SET titre='$titre',contenu='$contenu' WHERE id = ".$_POST['id_news']);
        }
 
        if ($result) 
          echo '<table><tr><th>'.ucfirst($action).'effectuée avec succès<br /><br /><a href="?">retour</a></th></tr></table>'; 
        else
            echo '<table><tr><th>Echec de la '.$action.'de la news<br /><br /><a href="javascript:windows.history.back();">retour</a></th></table>';
    }
    else 
        echo '<table><tr><th>Veuilez entrer un titre et un contenu pour créer uen nouvelle news...<br /><br />
        <a href="javascript:window.history.back()";>retour</a></th></tr></table>';
}
else
{
?>
<TABLE>
  <tr>
    <TH>Modifier</TH>
    <TH>supprimer</TH>
    <th>titre</th>
    <th>date</th>
  </tr>
  <?php
        $retour = mysql_query('SELECT * FROM news ORDER BY id desc');
        while($donnees = mysql_fetch_array($retour))
        {
  ?>
  <tr>
    <td><a href="rediger_news.php.op=edit&id=<?php echo $donnees['id']; ?>"></a>Modifier</td>
    <td><a href="?op=delete&id=<?php echo $donnees['id']; ?>">Supprimer</a></td>
    <td><?php echo stripslashes($donnees['titre']); ?></td>
    <td><?php echo date('d/m/Y', $donnees['timestamp']); ?> </td>
  </tr>
  <?php
        }
  ?>
</TABLE>
<?php
}
?>
</body>
Par contre après insertion dans ta base, tu vérifies si les données sont bien dedans ? Je parle directement dans la base pas avec le fichier php.
Kerod est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 18h03   #12
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
Je vais essayer de modifier, merci
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 18h07   #13
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
maintenant, quand j'écris une news, ça me renvoie systématiquement erreur lors de la création de la news ???
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 18h20   #14
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
En fait, je crois que j'ai un problème au niveau de ma base de donnée : je n'arrive pas à y accéder...
Peut-être est-ce l'explication du problème ?
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 19h25   #15
Membre Expert
 
Avatar de Anduriel
 
Homme
Étudiant
Inscription : février 2004
Messages : 2 168
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : février 2004
Messages : 2 168
Points : 1 277
Points : 1 277
Vu les erreurs ça serait pas étonnant... Mais ton code à l'air correct.
Anduriel est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/06/2006, 19h41   #16
Membre chevronné
 
Avatar de kankrelune
 
Inscription : décembre 2005
Messages : 766
Détails du profil
Informations forums :
Inscription : décembre 2005
Messages : 766
Points : 745
Points : 745
Petite modif... remplace

Code :
1
2
3
4
5
 
if(isset($_POST['id']))
	$id = strip_tags($_POST['id']);
		elseif(isset($_GET['id']))
			$id = strip_tags($_GET['id']);
par

Code :
1
2
3
4
5
 
if(isset($_POST['id']))
	$id = (int)$_POST['id'];
		elseif(isset($_GET['id']))
			$id = (int)$_GET['id'];
Pour le reste je n'ais pas le temps de regarder ton code maintenant mais je ne vois pas ce qui ne te plais pas dans le mien... par contre quelque chose me choque dans ce code c'est que les liens/actions de suppression et de modification seront accessible à tout le monde donc n'importe qui pourra supprimer tes news... ce qui est plutot génant... .. .

@ tchaOo°
kankrelune est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/06/2006, 17h34   #17
Invité régulier
 
Inscription : juin 2005
Messages : 49
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 49
Points : 6
Points : 6
En fait, j'ai tout modifié mais le problème persiste...
maintenant, il n'y a pas de message d'erreur mais sous liste_news.php il n'y a aucune news même si je remplis sous rediger_news.
A votre avis d'où vient le problème ?
merci

PS. pour la sécurité, je compte mettre un .htaccess. Qu'en pensez vous ?
merci
guiguistuder est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/06/2006, 02h10   #18
Membre chevronné
 
Avatar de kankrelune
 
Inscription : décembre 2005
Messages : 766
Détails du profil
Informations forums :
Inscription : décembre 2005
Messages : 766
Points : 745
Points : 745
Citation:
Envoyé par guiguistuder
En fait, j'ai tout modifié mais le problème persiste...
maintenant, il n'y a pas de message d'erreur mais sous liste_news.php il n'y a aucune news même si je remplis sous rediger_news.
A votre avis d'où vient le problème ?
merci

PS. pour la sécurité, je compte mettre un .htaccess. Qu'en pensez vous ?
merci

Je regarderais ça quand j'aurais deux minutes... .. .

Pour le .htaccess ça dépend... il protègera quoi les pages d'édition, tout... .. ?

S'il protège les pages d'édition oui ça suffit mais on verra quand même les liens d'édition/suppression... ça n'est pas grave mais c'est pas super propre... si le .htaccess protège tout et bien ça ne sert à rien puisque le membre devra être logué pour pouvoir voir les news il pourra donc les supprimer... à moins que ça soit des news juste pour les admin et que les membres n'y aient pas accès... .. .

@ tchaOo°

ps : J'ais géré les attaque CSS mais il reste des vulnérabilités au SQL injection dans le code que je donne... je verrais ça quand je me mettrais dessus... .. .
kankrelune est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h20.


 
 
 
 
Partenaires

Hébergement Web