Reputation: 1580
I have a form in php where I need to select value from DB (phpmyadmin) using php. When I add my code its not working. Can anyone please check this code?
<form role="form" action="test.php" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Category Name">
</div>
<div class="form-group">
<label for="code">Code:</label>
<select>
<?php
/* change character set to utf8 */
if (!mysqli_set_charset($conn, "utf8")) {
printf("Error loading character set utf8: %s\n", mysqli_error($conn));
exit();
} else {
$rslt=mysqli_query($con,"SELECT * from category") or die(mysqli_error($conn));
}
while ($row = mysql_fetch_array($rslt)){
echo $row;
echo "<option value=\"owner1\">" . $row['code'] . "</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="rank">Rank:</label>
<input type="text" class="form-control" name="rank" id="rank" placeholder="Enter Category Rank ">
</div>
<div class="form-group">
<label for="tag">Tags:</label>
<input type="text" class="form-control" name="tag" id="tag" placeholder="Enter Category tag ">
</div>
<button type="submit" class="btn btn-default">Done</button>
</form>
Upvotes: 0
Views: 1560
Reputation: 16772
Moving forward from the comments, this is what was needed:
Instead of:
while($row = mysql_fetch_array($sql)){
Should have been:
while($row = mysqli_fetch_assoc($rslt){
Notice: There are a few other warnings too. But that's only if you care. cheers
Upvotes: 2