I have a table item (id
, name
, content
, categories id
(foreign key table category)) and a category table (id
, title
)
name
: type textcontent
: textareacategories_id
: select dynamics related to the category table
Inserting the item table that works very well but in the modification. I have a problem with the dynamic select to the list of categories, not pick me a choice that I chose to add a article.
How I can get the value of the select tag? <select> <option></option> </select>
<?php
include 'dbconnect.php';
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM articles WHERE id ='".$id."'");
$res = mysql_fetch_assoc($sql);
if (@$_REQUEST['do'] == "update") {
$m_id = $_POST['id'];
$nom = $_POST["nom"];
$contenu = $_POST["contenu"];
$categories_id = $_POST["categories_id"];
$sql = mysql_query("UPDATE articles SET nom='$nom', contenu='$contenu', categories_id='$categories_id' WHERE id =' $m_id' ");
if($sql)
header("Location:listArticles.php");
else
header("Location:updateArticle.php");
}
?>
<html lang="en">
<body class="nav-md">
<?php if (isset($_GET['id']) && $_GET['id'] == $id) { ?>
<form action="" method="post" accept-charset="utf-8">
<table>
<td>Nom: <input type ="text" name ="nom" value="<?php echo $res['nom'] ?>"></td>
</br>
<td>Contenu: <textarea name ="contenu"><?php echo $res['contenu'] ?></textarea></td>
</br>
<td>
Categories:
<select class="form-control" name="categories_id" value="<?php echo $res['categories_id'] ?>" >
<option></option>
</select>
</td>
<td>
<button type="submit" class="btn btn-success" name ="do" value="update">Modifier</button>
</td>
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
</table>
</form>
<?php } ?>
</body>
</html>
That is what the page currently looks like: