I am trying to display product categories from my database, but the option are just blank, The database is connected as I get no error messages at all, so I was just wondering if anyone could give me some assistance. I have tried to change my variable with the database text but still does not work.
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-awsomecssfont-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>
Advertisement
Answer
Well i found the error, you’re using dollar with key name
$p_cat_id = $row_p_cats['$p_cat_id']; $p_cat_title = $row_p_cats['$p_cat_title'];
it should be like
$p_cat_id = $row_p_cats['p_cat_id']; $p_cat_title = $row_p_cats['p_cat_title'];