Eléphant du PHP |
258 Messages
31 juil. 2005, 11:05
salut à tous
je tiens à apporter la solution finale qui sert à modifier les données mysql via un formulaire html
voici mes bouts de code:
fichier config.php
<?php
$dbhost="sql.free.fr";
$dblogin="xxxxxx";
$dbpassword="xxxxxx";
$dbname="xxxxxx";
$dbtable='members';
$members=mysql_pconnect($dbhost,$dblogin,$dbpassword);mysql_selectdb($dbname);
mysql_select_db($dbname, $members);
$RecorMembers= mysql_query ("select * from $dbtable order by id desc");
$row_RecorMembers = mysql_fetch_assoc($RecorMembers);
$RecorId= mysql_query ("SELECT * FROM $dbtable where id='" . $_GET['num'] . "'");
$row_RecorId = mysql_fetch_assoc($RecorId);
//------ Chemin des images
define("image_path",'http://0540gbqu.free.fr/test/members/imgs/');
?>
fichier list_update.php:
<?php
require_once('config.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cypher.css" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<p class="text_titre">Administration</p>
<p class="text_sstitre">Page de modification des membres</p>
</div>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="header">
<tr>
<td><a href="index.php">Accueil</a></td>
<td><a href="form_add.php">- Ajout des membres</a></td>
<td><a href="list_update.php">- Modification</a></td>
<td><a href="list_delete.php">- Suppression</a></td>
<td><a href="list.php">- Liste des membres</a></td>
<td><a href="imgs/upload_imgs.php">- Upload d'une image</a></td>
</tr>
</table>
<br>
<table width="75%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4">
<?php do {?>
</td>
</tr>
<tr>
<td width="45%"><?php echo "<a href='form_update.php?num=".$row_RecorMembers['id']."'".">".$row_RecorMembers['id']."</a>";?></td>
<td width="55%" class="text_list"><?php echo $row_RecorMembers['name'];?></td>
<td width="55%" class="text_list"><?php echo $row_RecorMembers['prenom'];?></td>
<td width="55%" class="text_list"><?php echo $row_RecorMembers['imgs'];?></td>
</tr>
<tr>
<td colspan="4">
<?php } while ($row_RecorMembers = mysql_fetch_assoc($RecorMembers));?>
</td>
</tr>
</table>
</body>
</html>
fichier form_update.php:
<?php
require_once('config.php');
?>
<html>
<link href="cypher.css" rel="stylesheet" type="text/css">
<body>
<div align="center">
<p class="text_titre">Administration </p>
<p class="text_sstitre">Page de modification</p>
</div>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="header">
<tr>
<td><a href="index.php">Accueil</a></td>
<td><a href="form_add.php">- Ajout des membres</a></td>
<td><a href="list_update.php">- Modification</a></td>
<td><a href="list_delete.php">- Suppression</a></td>
<td><a href="list.php">- Liste des membres</a></td>
<td><a href="imgs/upload_imgs.php">- Upload d'une image</a></td>
</tr>
</table>
<form method="POST" action="valide_update.php">
<p>N°: <?php echo $row_RecorId['id']; ?><br>
Nom:<input type=text name="name" value="<?php echo $row_RecorId['name'];?>"><br>
Prénom:
<input type=text name="prenom" value="<?php echo $row_RecorId['prenom'];?>"><br>
Chemin:<input type=text name="imgs" value="<?php echo $row_RecorId['imgs'];?>">
<input type=hidden name="id" value="<?php echo $row_RecorId['id']; ?>">
<br>
<input type=submit value="Enregistrer">
</p>
</form>
</body>
</html>
fichier valid_update.php:
<?php
require_once('config.php');
// --- Récupération des données du formulaire
$id = $_POST['id'];
$name = $_POST['name'];
$prenom = $_POST['prenom'];
$img = $_POST['imgs'];
$RecorUpdate = mysql_query("UPDATE ".$dbtable." SET name='".$name."', prenom='".$prenom."', imgs='".$img."', date=now() WHERE id LIKE '".$id."'") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cypher.css" rel="stylesheet" type="text/css">
</head>
<body>
<p class="text_titre">Administration </p>
<p class="text_sstitre">Page de modification</p>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="header">
<tr>
<td><a href="index.php">Accueil</a></td>
<td><a href="form_add.php">- Ajout des membres</a></td>
<td><a href="list_update.php">- Modification</a></td>
<td><a href="list_delete.php">- Suppression</a></td>
<td><a href="list.php">- Liste des membres</a></td>
<td><a href="imgs/upload_imgs.php">- Upload d'une image</a></td>
</tr>
</table>
<p><br>
Bravo vous avez modifié:</p>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><?php echo $_POST['id'];?></td>
<td><?php echo $_POST['date'];?></td>
<td><?php echo $_POST['name'];?></td>
<td><?php echo $_POST['prenom'];?></td>
<td><?php echo $_POST['imgs'];?></td>
<td><img src="<?php echo image_path . $_POST['imgs'];
?>" hspace="0" vspace="0" border="0"></td>
</tr>
</table></body>
</html>
Merci à tous
Cordialement
Cypher_PHP