Eléphant du PHP |
258 Messages
31 juil. 2005, 10:57
salut à tous
je tiens à apporter la solution finale
elle sert à enregister des données dans une base de données mysql par un formulaire html.
voici mes bouts de code:
fichier config.php:
<?php
$dbhost="sql.free.fr";
$dblogin="xxxxxx";
$dbpassword="xxxxxxx";
$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 form_add.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 d'ajout des membres</p>
</div>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="header">
<tr class="header">
<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_add.php">
<span class="text_form">Nom:</span>
<input type=text name="name" value="<?php echo $name ?>">
<br>
<span class="text_form">Prénom:</span>
<input type=text name="prenom" value="<?php echo $prenom ?>"><br>
<span class="text_form">Image:</span>
<input type=text name="image" value="<?php echo $img ?>"><br>
<input type=submit value="Enregistrer">
</form>
</body>
</html>
fichier valid_add.php:
<?php
require_once('config.php');
// --- Récupération des données du formulaire
$prenom = $_POST['prenom'];
$name = $_POST['name'];
$img = $_POST['imgs'];
$RecorInsert = "INSERT INTO $dbtable VALUES ('', '$name', '$prenom', '$img', now())";
mysql_query($RecorInsert) 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 d'ajout des membres</p>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="header">
<tr class="table_RSS">
<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 ajouté:</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 . $row_RecorMembers['imgs'];
?>" hspace="0" vspace="0" border="0"></td>
</tr>
</table>
<p> </p>
</body>
</html>
Merci à tous
Cordialement
Cypher_PHP