cart button not working - php

Hi I have some more issues in my coding.when i have to changed my coding structure from div to table add to cart button not working.when it is working when it is in div but i have change to table cart button not working please help me to resolve my issue..
Code below is the old one (div) thats working fine here..
<?php if($microproduct['nr']){?>
<div class="product-box">
<div class="list" id="micropro">
<?php foreach ($microproduct['result'] as $resultmicroproduct){ ?>
<div class="row">
<div class="col-md-3">
<img src="images/feature-two-one.png" class="img-fluid mx-auto d-block">
</div>
<div class="col-md-7">
<div class="pro-desc">
<h5><?php echo $conn->stripval($resultmicroproduct['microsoft_product_legalname']);?></h5>
<p>Part number: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_partnumber']);?></p>
<p>Item Name: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_name']);?></p>
<p>Product family: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_family']);?></p>
<h4><i class="fa fa-rupee"></i> <?php echo $conn->stripval($resultmicroproduct['microsoft_product_price']);?></h4>
</div>
</div>
<div class="col-md-2">
<div class="wrapper-div">
<input min="1" type="number" name="quantity<?php echo $resultmicroproduct['microsoft_product_id'] ?>" class="form-control" id="quantity" value="1" autocomplete="off">
<br>
<?php $postvalue = base64_encode(json_encode($resultmicroproduct)); ?>
<input type="hidden" name="type" value="microsoft_product">
<button class="btn btn-dark btn-sm add_to_cart" id="<?php echo $resultmicroproduct['microsoft_product_id'] ?>" >Add to Cart</button>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
Code Below is the new one (table) cart button not working..
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Image</th>
<th>Product Description</th>
<th>Quantity & Cart</th>
</tr>
</thead>
<?php if($microproduct['nr']){?>
<tbody>
<?php foreach ($microproduct['result'] as $resultmicroproduct){ ?>
<tr class="product-box">
<td><img src="images/feature-two-one.png" class="img-fluid mx-auto d-block"></td>
<td>
<div class="pro-desc">
<h5><?php echo $conn->stripval($resultmicroproduct['microsoft_product_legalname']);?></h5>
<p>Part number: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_partnumber']);?></p>
<p>Item Name: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_name']);?></p>
<p>Product family: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_family']);?></p>
<h4><i class="fa fa-rupee"></i> <?php echo $conn->stripval($resultmicroproduct['microsoft_product_price']);?></h4>
</div>
</td>
<td>
<div class="wrapper-div">
<input min="1" type="number" name="quantity<?php echo $resultmicroproduct['microsoft_product_id'] ?>" class="form-control" id="quantity" value="1" autocomplete="off">
<br>
<input type="hidden" name="type" value="microsoft_product">
<button class="btn btn-dark btn-sm add_to_cart" id="<?php echo $resultmicroproduct['microsoft_product_id'] ?>">Add to Cart</button>
</div>
</td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
<tfoot>
<th>Image</th>
<th>Product Description</th>
<th>Quantity & Cart</th>
</tfoot>
</table>

You don't even have a form.
<form action ="?" method="?">
//your inputs and submit
</form>
What do you expect to happen if you don't define what to do?

Related

Show Detail of Data in Bootstrap Modal based on ID

I have some edit modal and i want it to show the detail of DATA in bootsrap modal based on ID. Here is my index code:
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?> </h1>
<div class="row">
<div class="col-lg-6">
<?= form_error('menu', '<div class="alert alert-danger" role="alert">','</div>'); ?>
<?= $this->session->flashdata('message'); ?>
Tambah User
<table class="table table-hover">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Nama</th>
<th scope="col">Email</th>
<th scope="col">Password</th>
<th scope="col">Role</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach ($userRole as $u) : ?>
<tr>
<th scope="row"><?= $i ; ?></th>
<td><?= $u['name']; ?> </td>
<td><?= $u['email']; ?> </td>
<td><?= $u['password']; ?> </td>
<td><?= $u['role']; ?> </td>
<td>
<a href="" class="badge badge-success" data-toggle="modal"
data-target="#editRoleModal">edit</a>
<a href="<?= base_url('admin/deleteuser/') . $u['id'];?>"
class="badge badge-danger">delete</a>
</td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
And here is my modal :
<!-- Modal Edit-->
<div class="modal fade" id="editRoleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<?= form_open_multipart('admin/usermanagement'); ?>
<div class="modal-body">
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="name" name="name" value="<?= $user['name']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="email" class="form-control" id="email" name="email" value="<?= $user['email']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="password" name="password"
value="<?= $user['password']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<select name="menu_id" id="menu_id" class="form-control">
<option value="">Select Role</option>
<?php foreach ($user_role as $u) : ?>
<option value="<?= $u['id']; ?>"><?= $u['role']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
For now It shows the data based on ID, but when i try to click edit button of another data, it show the same detail of one ID only.
I hope that every i click every data button, it shows different detail based on id. I've check similar case already but no one of them that work on my code. I just know my code need some jquery, but i just new on it.
like saad said, place it inside the loop
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?> </h1>
<div class="row">
<div class="col-lg-6">
<?= form_error('menu', '<div class="alert alert-danger" role="alert">','</div>'); ?>
<?= $this->session->flashdata('message'); ?>
Tambah User
<table class="table table-hover">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Nama</th>
<th scope="col">Email</th>
<th scope="col">Password</th>
<th scope="col">Role</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach ($userRole as $u) : ?>
<tr>
<th scope="row"><?= $i ; ?></th>
<td><?= $u['name']; ?> </td>
<td><?= $u['email']; ?> </td>
<td><?= $u['password']; ?> </td>
<td><?= $u['role']; ?> </td>
<td>
<a href="" class="badge badge-success" data-toggle="modal"
data-target="#editRoleModal<?=$i?>">edit</a>
<a href="<?= base_url('admin/deleteuser/') . $u['id'];?>"
class="badge badge-danger">delete</a>
<!-- Modal Edit-->
<div class="modal fade" id="editRoleModal<?=$i?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<?= form_open_multipart('admin/usermanagement'); ?>
<div class="modal-body">
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="name" name="name" value="<?= $u['name']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="email" class="form-control" id="email" name="email" value="<?= $u['email']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="password" name="password"
value="<?= $u['password']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<select name="menu_id" id="menu_id" class="form-control">
<option value="">Select Role</option>
<?php foreach ($user_role as $u2) : ?>
<option value="<?= $u2['id']; ?>"><?= $u2['role']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
</td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>

open Collapse sidebar with same DB id

I'm currently working on the forum section of my website.
I followed the link #CBroe suggest me on the comments and implemented offcanvas for my previous problem and now I have this:
<table class="table is-indent changes" id="newsTable">
<thead>
<th></th>
<th></th>
</thead>
<tbody>
<?php foreach($fetchNews as $data):
echo '<tr class="trNew btnSelect" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight" id=\''.$data['id'].'\'>' ?>
<td class="cell-60 responsive-hide" style="width: 100px;">
<img class="author width" src="<?php echo '../../resource/img/users_Initials/' . $data['autore'].'.png' ?>">
</td>
<td id="<?php echo $data['id']; ?>">
<input type="hidden" id="idNew" value="<?php echo $data['id']; ?>" data-value="<?php echo $data['id']; ?>">
<div class="content">
<div class="title" id="title"> <?php echo $data['titolo']; ?> </div>
<div class="metas">
<span class="author"><?php echo $data['autore']; ?> - </span>
<span class="data"><?php echo $data['data']; ?></span>
</div>
</div>
<?php endforeach;?>
</td>
</tr>
</tbody>
</table>
And this is the offcanvas the table below open:
<!--PANEL NEWS-->
<?php foreach($fetchNews as $data):?>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h1 id="newsTitolo"><?php echo $data['titolo']??''; ?></h1>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="forum-header">
<img class="author width" src="<?php echo '../../resource/img/users_Initials/' . $data['autore'].'.png' ?>">
<span class="name"><?php echo $data['autore']??''; ?></span>
<span class="time"><?php echo $data['data']??''; ?></span>
</div>
<div class="forum-content">
<div id="newsTesto" class="articolo">
<?php $Parsedown = new Parsedown();
echo $Parsedown->text(file_get_contents('post/'.$data['titolo'].'/'.$data['titolo'].'.txt')??''); ?>
</div>
<p> <?php echo $data['allegato']??'';?></p>
</div>
</div>
</div>
<?php endforeach;?>
<!--END PANEL NEWS-->
What I basically need to do is display the article with the same ID as the title on the table as this example image: table & panel that by clicking on the first title (ahaaa) it opens the corresponding article.
I tried some stuff like adding $data['id'] on both data-bs-target and data-bs-toggle of the and as id of the offcanvas but it didnt work

passing parameter to modal window with data-target is not working

I have designed one page consisting of one modal window which is opening with tag.
I want to pass some parameters to modal window which i will be using to populate table data based on the parameter value.It is working with one parameter but not working with another parameter.
Following is the HTML to open modal window......
<table id="MyTable1" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GMA_ACCESS_FLAG"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","OPTIONS"); ?></th>
</tr>
</thead>
<tbody>
<?php
if ($_SESSION['$language']="E") {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_desc,gma_module_id,module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id");
}
else {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_bldesc as grp_desc,gma_module_id,module_blname as module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id");
}
foreach ($groupdata as $groupdatalist) {
//$allids[]=$groupdatalist["gma_id"]; ?>
<tr>
<td><?php echo $groupdatalist["grp_desc"];?></td>
<td><?php echo $groupdatalist["module_name"];?></td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<td style="text-align:right;width:10px;"><input type="checkbox" name="accessflag[]" id="accessflag"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php else:?>
<td style="text-align:right;width:10px;"><input type="checkbox" checked name="accessflag[]" id="accessflag" width="10px"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php endif;?>
<td style="display:none;"><?php echo $groupdatalist["gma_grp_id"];?></td>
<td style="display:none;"><?php echo $groupdatalist["gma_module_id"];?></td>
<td style="display:none;"><input type="text" name="gmaid" id="gmaid" value="<?php echo $groupdatalist["gma_id"];?>"></td>
<!--<td style="display:none"><input type="text" name="allids[]" value="<//?php echo "{$groupdatalist['gma_id']}"?>"/></td>-->
<td>
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
<a href="#" class="btn btn-light btn-sm shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
</span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Here is the modal window HTML.....
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">Menu List</h6>
</div>
<div class="modal-body">
<div class="control-container" style="padding:10px;">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php //session_start();
if (!empty($_SESSION['$SaveMsg'])) { echo $_SESSION['$SaveMsg']; }
unset($_SESSION['$SaveMsg']);
?>
</label>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="grpid" id="grpid"
value="" readonly required maxlength="50" style="width:100%;display:none;" autofocus />
<input class="text-control" type="text" name="grpname" id="grpname"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="moduleid" id="moduleid"
value="" readonly required maxlength="50" style="width:100%;display:none" autofocus />
<input class="text-control" type="text" name="modulename" id="modulename"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<?php $gmaid= "<script>document.writeln(gmaid);</script>";
echo $gmaid;?>
<!--table starts here -->
<table id="MyTable2" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","MENUNAME"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>-->
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","ACCESS_FLAG"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","OPTIONS"); ?></th>-->
</tr>
</thead>
<tbody>
</table>
<!-- table ends here -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
<i class="fa fa-close"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","CANCEL"); ?>
</button>
<button type="submit" name="updmenuperm" formnovalidate class="btn btn-primary"> <!--onclick="DispMsg(<//?php echo "'".$_SESSION['AlertMsg']."'";?>)"-->
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
</div>
Above code is working perfectly but if i am using another value as parameter it is not opening the modal window at all.
for ex. if i am using $groupdatalist['gma_id'] which is integer value, it is not opening modal window.
Multiple issues here.
First a </div> is missing at the end.
Then you are defining $groupdatalist in a foreach, but trying to use it outside the loop:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
If you want one modal per <td> you have to move your modal into the foreach loop.
Finally, you call the modal using $groupdatalist['gma_id']
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
but the modal ID is define using a different variable : $groupdatalist['gma_grp_id']:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>"

My view attendance table not pulling table from Database

When I attempt to view an attendance that was already filled, it brings up the table, but it is empty. My SQL and Apache error logs do not give any errors and as far as im concerned, the database table names do match.
This is my PHP code for the View All. I've also tried defining $date=date("Y-m-d); before the mysqli_query and changing the "where date=$_POST[date]" to "date=$date" but to no avail
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<form action="AttendanceTable.php" method="post">
<table class="table table-striped">
<tr>
<th>#serial Number</th> <th>Student Name</th> <th>Roll Numbers</th> <th>Attendance Status</th>
</tr>
<?php
$result=mysqli_query($con, "select * from attendance_records where date=$_POST[date]");
$serialnumber=0;
$counter=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['student_name']; ?>
</td>
<td> <?php echo $row['roll_number']; ?> </td>
<td>
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Present"> Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Absent"> Absent
</td>
</tr>
<?php
$counter++;
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
This is my PHP code for the page before the view attendance
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<table class="table table-striped">
<tr>
<th>Serial Number</th> <th>Dates</th> <th>Show Attendance</th>
</tr>
<?php
$result=mysqli_query($con, "SELECT distinct date FROM attendance_records");
$serialnumber=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td>
<form action="show_attendance.php" method="POST">
<input type="hidden" value="<?php echo $row['date'] ?>" name="date">
<input type="submit" value="Show Attendance" class="btn btn-primary">
</form>
</td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
You don't have any quotes, so your WHERE condition
where date=$_POST[date]
is expanded to where date=2019-02-17. MySQL happily computes 2019 - 2 - 17 = 2000. No date matches that so you get back zero records.
You should use a prepared statement for queries that take parameters like this, that way the database adds the necessary quotes and escape sequences http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

How to initiate if else statement inside a td tag

In my database, I have a table column that has a filepath for images. The filepath's name is photo Some of my rows don't have a filepath. Inside my while loop forshowing the table, I would like to add a condition that if there is no filepath, it would prompt the text "User did not upload a photo yet." and when it has filepath, I can show the filepath and link it with a target blank.
This is my php file for it.
<?php require_once 'process.php';
session_start();
$role = $_SESSION['sess_userrole'];
$name = $_SESSION['sess_name'];
if(!isset($_SESSION['sess_username']) && $role!="admin"){
header('Location: index.php?err=2');
}
?>
<html>
<head>
<title>User Accounts</title>
<link rel="icon" href="isalonlogo.png">
<link rel="stylesheet" href="css2/bootstrap.min.css">
<script src="css/jquery-3.3.1.slim.min.js"></script>
<script src="css/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="css/bootstrap.min.js"></script>
</head>
<body>
<?php
if (isset($_SESSION['message'])):?>
<div class="alert alert-<?=$_SESSION['msg_type']?>">
<?php
echo $_SESSION['message'];
unset ($_SESSION['message']);?>
</div>
<?php endif ?>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<span class="navbar-brand" href=""><?php echo " " . "$name"?>, here are the Stylist user lists.</span>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>User Lists</li>
<li><?php echo $_SESSION['sess_username'];?></li>
<li>Logout</li>
</ul>
</div>
</div>
</div>
<br> <br> <br>
<div class="container">
<?php
$mysqli = new mysqli("localhost","id7508046_root","123123123as","id7508046_isalon") or die(mysqli_error($mysqli));
$result = $mysqli->query("SELECT * FROM stylist ") or die($mysqli->error);
?>
<div class="row justify-content-center" width="80%">
<table class="table">
<thead>
<tr>
<th>UserName</th>
<th>Name</th>
<th>Image</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php
while($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['name'] ?></td>
// THIS PART HERE IS THE PROBLEM
<td><?php if(strcmp($row['photo'],"") == 0): {echo 'Ola';
}else:
{echo '<img src="'.$row['photo'].'">';
}
endif;
?></td>
<td>
<a href="userlist.php?edit=<?php echo $row['stylist_id']; ?>"
class="btn btn-info">Edit</a>
<a href="process.php?delete=<?php echo $row['stylist_id']; ?>"
class="btn btn-danger">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
<?php
function pre_r($array){
echo '<pre>';
print_r($array);
echo '</pre>';
}
?>
<br>
<br>
<div class="container justify-content-center">
<h5 class=" justify-content-center">Admin <?php echo $name;?>, create or edit an account here.</h5>
<form action="process.php" method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="form-group">
<label>UserName</label>
<input type="text" name="username" class="form-control" value="<?php echo $username;?>" placeholder="Enter new user Username" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="text" name="password" class="form-control" value="<?php echo $password;?>" placeholder="Enter new user Password" required>
</div>
<div class="form-group">
<?php
if($update == TRUE): ?>
<button type="submit" class="btn btn-primary" name="update">Update</button>
<input type="button" class="btn btn-primary" name="reset" value="Reset" onclick="window.location.href='stylistUserlist.php'">
<?php
else: ?>
<button type="submit" class="btn btn-primary" name="save">Save</button>
<input type="button" class="btn btn-primary" name="reset" value="Reset" onclick="window.location.href='stylistUserlist.php'">
<?php
endif; ?>
</div>
</form>
</div>
</div>
</body>
Try
<td>
<?php if(!empty(trim($row['photo']))): ?>
<img src="<?php echo $row['photo'];?>"/>
<?php else: ?>
User did not upload a photo yet
<?php endif; ?>
</td>
Use below code for TD as you currently added same code in if and else both instead of using if else you can use the ternary operator.
<td>
<?php $photo = (isset($row['photo'])) ? $row['photo'] : "";
echo ($photo) ? "'. <img src=".$photo."> .'" : ""; ?>
</td>

Categories