Merci pour vos réponses.
La ligne 7 est
if (($_POST['submitted']) && (!$_GET['modify_id']))
Je suis vraiment un débutant. Je suis pas à pas le livre « Coder pour le web » de Charles Wyke-Smith et celui-ci ne tient simplement pas compte de isset nulle part, ce qui veut dire que j'ai dû l'ajouter moi-même à quelques endroits pour que ça fonctionne.
La partie de code originale est
if (($_POST['submitted']) && (!$_GET['modify_id'])) {
// the user has submitted a new listing
$category=($_POST['category']);
$topic_name=($_POST['topic_name']);
$topic_description=($_POST['topic_description']);
$topic_url=($_POST['topic_url']);
//write to database
mysql_query ("INSERT into ref_links (ref_categories_id, topic_name, topic_desc, topic_url) VALUES ('$category', '$topic_name', '$topic_description', '$topic_url')", $connectID)
or die ("Unable to insert record into database");
print "Record successfully added";
} elseif ((!$_POST['submitted']) && ($_GET['modify_id'])) {
// the admin page has passed ID of record to be updated
$id = ($_GET['modify_id']);
$this_Record = mysql_query("SELECT ref_links.*,ref_categories.category_name, ref_categories.id AS cat_id FROM ref_links, ref_categories WHERE ref_categories.id = ref_links.ref_categories_id AND ref_links.id = '$id'", $connectID)
or die ("Can't read the this record.");
while ($record_data = mysql_fetch_array($this_Record, MYSQL_ASSOC)) {
foreach ($record_data as $key => $value) {
print "$key => $value<br />";
}
} // end while loop
} elseif (($_POST['submitted']) && ($_GET['modify_id'])) {
// the user has submitted the form to update a listing
} else {
// The user has loaded the page to enter a new listing
// do nothing - just let the page load
}
mais ça ne fonctionne pas.
@Aureusms: Je ne suis pas certain de bien comprendre ce que vous voulez dire...
En fait, ce que je dois tester, c'est une réponse envoyée à partir d'un page différente et qui passe par la page ci-haut pour inscrire des infos dans MySQL.
Le code de l'autre page est le suivant
<?php include ("connection_to_database_open.php");
if (isset($_GET['delete_id']))
{
if ($_GET['delete_id'])
{
$id=($_GET['delete_id']);
$success=mysql_query ("DELETE FROM ref_links WHERE id=$id",$connectID)
or die ("Unable to delete record from database");
if ($success)
{
print "Record successfully deleted";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Links Admin</title>
</head>
<body>
<?php
//query the database
$myResult = mysql_query('SELECT ref_links.*, ref_categories.category_name FROM ref_links, ref_categories WHERE ref_links.ref_categories_id=ref_categories.id', $connectID)
or die ("Unable to select from database");
//loop through the returned records
print '<table border="1">'."\n";
while ($row = mysql_fetch_array($myResult, MYSQL_ASSOC)) {
//category heading only written out if a listing is in diff cat from previous listing
//$thisCat is used to test if a new heading needs to be written out
$thisCat= $row['category_name'];
$lastCat='';
if ($lastCat<>$thisCat) { // true first time($lastCat not set), and each time a new category is found
//then write out a table heading with the category name
print '<th colspan="6" align="left">'; //heading spans all columns of table
print "<h3>".$row['category_name']."</h3>"; // print the next category heading
print "</th>\n";
}
print '<tr>';
print '<tr>'."\n";
print '<td>'.$row['topic_name'].'</td>'."\n";
print '<td class="description">'.$row['topic_desc'].'</td>'."\n";
print '<td><a href="'.$row['topic_url'].'" target="_blank">'.$row['topic_url'];
print'</a></td>';
$id =$row['id'];
print '<td><a href="links_form.php?modify_id='.$id.'">Edit</td>';
print '<td><a href="';
print ($_SERVER['PHP_SELF']);
print '?delete_id='.$id.'">Delete</a></td>';
print '</tr>'."\n";
// finally, we store the current category so next time the loop repeats,
// we can tell if the next item is in a new category or not
// if so, we write out a new heading - see if ($lastCat<>$thisCat) above
$lastCat = $row['category_name'];
}
print '</table>'."\n";
?>
</body>
</html>
<?php include ("connection_to_database_close.php");?>
Désolé pour la longueur du code. J'imagine que des gens qui s'y connaissent plus que moi verront immédiatement où est le problème! Merci beaucoup..
Post Scriptum -> Est-ce que je peux essayer d'utiliser isset pour les deux variables, pour que
if (($_POST['submitted']) && (!$_GET['modify_id']))
soit setté pour les deux? e.g. Quelque chose comme
if (isset($_POST['submitted']) && (!$_GET['modify_id']))
??
Merci