I don't realy know where to start but here goes.
I have made a php script utilising pieces of different scripts. What I want is, when accessing this script, the top part shows all the members full name that are in the database (db field is "membres").
Beside each members name, I would like to have a radiobutton (this would be to select the record). Bellow would be a "DELETE" and a "MODIFY" button. You know what does are for!
Also, there would be another button name "ADD". This would be to add a new member to the database. The different fields per records are;
Last Name
First Name
Address
Telephone #
Frequency
Email
I don't know but maybe this would be easier in different files, ie: 1 php script file for adding, 1 for deleting and 1 for modifying.
I don't know where to start or end for that matter.
Here is what the script (up to now) looks like. The Print of records is OK and the adding of record using the " <input type="Submit" name="submit" value="Soumettre l'information'">" is ok.
The problem lies where I want the script to be clean and easy to read, if possible. Right now, I dont know where i'm heading and need some help. Thanks in advance.
Here is the file:
<html>
<body>
<?php
include("dbconnect.php");
$query = "SELECT * FROM membres ORDER BY nom ASC";
$mysql_result = mysql_query($query, $mysql_link);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE membres SET nom='$nom',prenom='$prenom',adresse='$adresse',telephone='$telephone',fréquence='$fréquence',email='$email' WHERE id=$id";
} else {
$sql = "INSERT INTO membres (nom,prenom,adresse,telephone,fréquence,email) VALUES ('$nom','$prenom','$adresse','$telephone','$fréquence','$email')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Ce membre a été mise-à-jour!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM membres WHERE id=$id";
$result = mysql_query($sql);
echo "Ce membre a été éffacé!<p>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
print("<table border=5 cellpadding=1 cellspacing=1 align=center width=500><tr>");
$totalcols = 3;
$colsprinted = 0;
while ($myrow = mysql_fetch_row($mysql_result))
{
if($totalcols == $colsprinted)
{
print("</tr><tr>");
$colsprinted = 0;
}
else
{
printf("<td nowrap>%s %s<input type=\"radio\" name=\"check\" value=\"$delete\"></td>", $myrow[1], $myrow[2]);
$colsprinted++;
}
}
print("</tr>");
echo "</table>\n";
}
?>
<P>
Pour éffacer un membre de la basse de donnée, appuyer sur <b>"EFFACER"</b> au coté du nom.<br>
Pour ajouter un membre dans la base de donnée, entrer les infomations dans les case ci-dessous.<br>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM membres WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$nom = $myrow["nom"];
$prenom = $myrow["prenom"];
$adresse = $myrow["adresse"];
$telephone = $myrow["telephone"];
$fréquence = $myrow["fréquence"];
$email = $myrow["email"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
<form>
<b>Nom:</b><input type="Text" name="nom" value="<?php echo $nom ?>"><br>
<b>Prénom:</b><input type="Text" name="prenom" value="<?php echo $prenom ?>"><br>
<b>Adresse:</b><input type="Text" size="50" name="adresse" value="<?php echo $adresse ?>"><br>
<b>Téléphone:</b><input type="Text" name="telephone" value="<?php echo $telephone ?>"><br>
<b>Fréquence:</b><input type="Text" name="fréquence" value="<?php echo $fréquence ?>"><br>
<b>Email:</b><input type="Text" name="email" value="<?php echo $email ?>"><br>
<input type="Submit" name="submit" value="Soumettre l'information'">
</form>
<?php
}
?>
<p><center><a href="test.php">Cliquer ICI </a> pour entrer un autre membre.
<p><center><a href="javascript: window.close();">Cliquer ICI</a> Pour fermer cette fenêtre.
Merci!
</body>
</html>