选项未显示“ Php我的管理员”的结果

时间:2019-01-11 03:58:41

标签: php html web phpmyadmin

我正在尝试显示数据库中的产品类别,但该选项只是空白,数据库已连接,因为我根本没有收到任何错误消息,所以我只是想知道是否有人可以给我一些帮助。我试图用数据库文本更改变量,但仍然无法正常工作。

Phpmyadmin的图片

Image of Phpmyadmin

<?php 
// db.php
    $con = mysqli_connect("localhost","Marcus","*****","electronicshub",);
    if (!$con) {
        die("Connection Error: " . mysqli_connect_error())
    }
?>
<?php
    include("includes/db.php")
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Insert Products</title>
    <link rel="stylesheet" href="css/bootstrap-337.min.css">
    <link rel="stylesheet" href="font-awsome\css\font-awesome.min.css">
</head>
<body>
<div class="row"><!-- row Begin -->
    <div class="col-lg-12"><!-- col-lg-12 Begin -->
        <ol class="breadcrumb"><!-- breadcrumb Begin -->
            <li class="active"><!-- active Begin -->
                <i class="fa fa-dashboard"></i> Dashboard / Insert Products
            </li><!-- active Finished --> 
        </ol><!-- breadcrumb Finished -->
    </div><!-- col-lg-12 Finished -->
</div><!-- row Finished -->
<div class="row"><!-- row Begin -->
    <div class="col-lg-12"><!-- col-lg-12 Begin -->
        <div class="panel panel-default"><!-- panel panel-default Begin -->
            <div class="panel-heading"><!-- panel-heading Begin -->
                <h3 class="panel-title"><!-- panel-title Begin -->
                    <i class="fa fa-money fa-fw"></i> Insert Product
                </h3><!-- panel-title Finished -->
            </div><!-- panel-heading Finished -->
            <div class="panel-body"><!-- panel-body Begin -->
                <form method="post" class="form-horizontal" enctype="multipart/form-data"><!-- form-horizontal Begin -->
                    <div class="form-group"><!-- form-group Begin -->
                        <label class="col-md-3 control-label">Product Title</label>
                        <div class="col-md-6"><!-- col-md-6 Begin -->
                            <input name="product_title" type="text" class="form-control" required>
                        </div><!-- col-md-6 Finished -->
                    </div><!-- form-group Finished -->
                    <div class="form-group"><!-- form-group Begin -->
                        <label class="col-md-3 control-label">Product Category</label>
                        <div class="col-md-6"><!-- col-md-6 Begin -->
                            <select name="product_cat" class="form-control"><!-- form-control Begin -->
                                <option>Select a Category Product</option>
                                <?php
                                    $get_p_cats ="SELECT * FROM product_categories";
                                    $run_p_cats = mysqli_query($con,$get_p_cats);
                                    while ($row_p_cats=mysqli_fetch_array($run_p_cats)) {
                                        $p_cat_id = $row_p_cats['$p_cat_id'];
                                        $p_cat_title = $row_p_cats['$p_cat_title'];
                                        echo "
                                            <option value='$p_cat_id'> $p_cat_title</option>
                                        ";
                                    }
                                ?>
                            </select><!-- form-control Finished -->
                        </div><!-- col-md-6 Finished -->
                    </div><!-- form-group Finished -->
                </form><!-- form-horizontal Finished -->
            </div><!-- panel-body Finished -->
        </div><!-- panel panel-default Finished -->
    </div><!-- col-lg-12 Finished -->
</div><!-- row Finished -->


<script src="js/jquery-331.min.js"></script>
<script src="js/bootstrap-337.min.js"></script>

</body>
</html>

2 个答案:

答案 0 :(得分:1)

好吧,我发现了错误,您使用的键名是

$p_cat_id = $row_p_cats['$p_cat_id'];
$p_cat_title = $row_p_cats['$p_cat_title'];

应该像

$p_cat_id = $row_p_cats['p_cat_id'];
$p_cat_title = $row_p_cats['p_cat_title'];

答案 1 :(得分:-1)

在您的代码中

$p_cat_id = $row_p_cats['$p_cat_id'];
$p_cat_title = $row_p_cats['$p_cat_title'];

您在行数组变量中使用了变量$ p_cat_id而不是字符串'p_cat_id'(请注意,不需要$)

所以修改后的代码将是

$p_cat_id=$row_p_cats['p_cat_id'];
$p_cat_title=$row_p_cats['p_cat_title'];

希望这可以解决您的问题。