I was trying to get selected value selected from database, but it does not work for some reason. I do not know what do I need to change, I am using function to store articles in database, and I am using the same function to get article that is selected in database. Function artikli:
function article() {
$link = new mysqli("localhost", "xxx", "xxx", "xxx");
$link->set_charset("utf8");
$sql=mysqli_query($link, "SELECT * FROM `artikli` ORDER BY `Id` ASC ");
echo '<option value="">Select article: </option>';
while($record=mysqli_fetch_array($sql)){
echo '<option value= "' .$record['Id']. '">' . $record['ArtCode'] ."-|-". $record['ArtName'] . ' </option>';
}
}
In insert form this function works and insert an article. Now, in edit form, I want to get an article that is inserted. First I retrieve article from another table and I get value.
$article = $r['ArtPalArticle'];
I get for ex. value 18. All values are integers.
$article = 18;
<div class="col-xs-12">
<label>Article</label>
<select class="form-control" name="article" value = "<?php echo $article; selected?>">
<option value=<?php echo $article?> selected></option>
<?php article(); ?>
</select>
</div>
Could anyone give me hint, do I need to change function or I missed the code below function. It would be better for me to keep function same and change code below in select section