Product Picture not show i - php

This code is use add and update product but image not showing. i think its paths error but I cant resolve it.kindly find error in this code where I mistake.Product images not showing on the product page .
i follow A series I write a same code but not working but in tutorial working fine .Tankx in advance
Product.Php
<?php
require('top.inc.php');
if(isset($_GET['type']) && $_GET['type']!=''){
$type=get_safe_value($con,$_GET['type']);
if($type=='status'){
$operation=get_safe_value($con,$_GET['operation']);
$id=get_safe_value($con,$_GET['id']);
if($operation=='active'){
$status='1';
}else{
$status='0';
}
$update_status_sql="update product set status='$status' where id='$id'";
mysqli_query($con,$update_status_sql);
}
if($type=='delete'){
$id=get_safe_value($con,$_GET['id']);
$delete_sql="delete from product where id='$id'";
mysqli_query($con,$delete_sql);
}
}
$sql="select product.*,categories.categories from product,categories where product.categories_id=categories.id order by product.id desc";
$res=mysqli_query($con,$sql);
?>
<div class="content pb-0">
<div class="orders">
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<h4 class="box-title">Products </h4>
<h4 class="box-link">Add Product </h4>
</div>
<div class="card-body--">
<div class="table-stats order-table ov-h">
<table class="table ">
<thead>
<tr>
<th class="serial">#</th>
<th>ID</th>
<th>Categories</th>
<th>Name</th>
<th>Image</th>
<th>MRP</th>
<th>Price</th>
<th>Qty</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$i=1;
while($row=mysqli_fetch_assoc($res)){?>
<tr>
<td class="serial"><?php echo $i?></td>
<td><?php echo $row['id']?></td>
<td><?php echo $row['categories']?></td>
<td><?php echo $row['name']?></td>
<td><img src="<?php echo PRODUCT_IMAGE_SITE_PATH.$row['image']?>"/></td>
<td><?php echo $row['mrp']?></td>
<td><?php echo $row['price']?></td>
<td><?php echo $row['qty']?></td>
<td>
<?php
if($row['status']==1){
echo "<span class='badge badge-complete'><a href='?type=status&operation=deactive&id=".$row['id']."'>Active</a></span> ";
}else{
echo "<span class='badge badge-pending'><a href='?type=status&operation=active&id=".$row['id']."'>Deactive</a></span> ";
}
echo "<span class='badge badge-edit'><a href='manage_product.php?id=".$row['id']."'>Edit</a></span> ";
echo "<span class='badge badge-delete'><a href='?type=delete&id=".$row['id']."'>Delete</a></span>";
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
require('footer.inc.php');
?>
When I upload pic this error show in console and pic not show on front end I try to solve couple of hours but I cant find error .i know I have little bit mistake but I cant find it.
GET http://localhost/AdminPanel/media/product/http://127.0.0.1/php/ecom/media/product/929442919_111.png 403 (Forbidden)

GetSet is right. The error is pretty quick to spot in the GET statement and the problem comes from here:
PRODUCT_IMAGE_SITE_PATH.$row['image']
I'm assuming that PRODUCT_IMAGE_SITE_PATH = http://localhost/AdminPanel/media/product/ so you'll probably need to clean the data in $row['image'] to remove the unnecessary stuff.
Important: this is not a recommended solution, but it will get you closer to something a little more logical.
Change:
PRODUCT_IMAGE_SITE_PATH.$row['image']
To:
PRODUCT_IMAGE_SITE_PATH . str_replace($row['image'], 'http://127.0.0.1/php/ecom/media/', '')
Ideally there would be a lot more data validation and whatnot going on before spitting this HTML out to a browser, but this should get you part of the way there.

Related

how to create link for one user id from datatable and view only that user id detail in next page?

I have a function manage_child which it is in a datatables that show all children details. My problem is I want to view only one child details at another pages. I have tried to implement this example of code in my function but it didnt work since I call it like this:
`<td><a href="?pages=child_view"</a><?php_e($child_id); ?></td>`
I have link the page where the details should go but it didn't work. I am still in my basic using php and I use mysqli for the database.
This is the example that I tried to implement in my code but still doesn't work.
echo "<td>".$row[id]."</td>";
echo "<td>".$row[l_name]."</td>";
echo "<td>".$row[f_name]."</td>";
echo "<td>".$row[ssn]."</td>";
this is my code
function manage_child(){
$query = query("SELECT * FROM register_child");
confirm($query);
?>
<div class='container-fluid'>
<div class='row'>
<h1 class="page-header">Children
<small>Information</small>
</h1>
<div class="panel-body">
<div class="dataTable_wrapper">
<table width="50%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>No</th>
<th>CHild ID</th>
<th>Child IC</th>
<th>Name</th>
<th>Address</th>
<th>Mother name</th>
</tr>
</thead>
<tbody>
<?php
$bil = 0;
while($row = fetch_array($query)) {
$password = $row['ic_no'];
$child_id = $row['child_id'];
$child_name = $row['child_name'];
$address = $row['address'];
$mother_name = $row['mother_name'];
$bil++;
?>
<tr class="odd gradeX">
<td><?php echo $bil; ?></td>
<td><?php _e($password);?></td>
<td><a href="?pages=child_view"</a><?php _e($child_id); ?></td>
<td><?php _e($child_name); ?></td>
<td><?php _e($address); ?></td>
<td><?php _e($mother_name); ?></td>
<?php
}// End of while
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
}

how can show 5 millons of data datatable in codeigniter

I am new in php. I want to show 5 Millions of record from my database in php in codeignter. I am using select star sql query to select table. It's working good but takes long time in loading data into datatable.
Any help would be appreciated.
Thanks in Advance.
<?php
include('layout/header.php');
include('layout/sidebar.php');
?>
<div data-widget-group="group1">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h2>Data Tables</h2>
<div class="panel-ctrls"></div>
</div>
<div class="panel-body no-padding table-responsive">
<form action="<?= base_url(); ?>signin/sendemailstudent" method="post">
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th style="padding-right:100px;">S.No</th>
<th>School</th>
<th>Date Of Admission</th>
<th>Register Serial</th>
<th>Student Name</th>
<th>Date Of Birth</th>
<th>Father Name </th>
<th>Phone </th>
<th>Email</th>
<th>Pincode</th>
<th>Class To Which Admitted</th>
<th>Class From Which Withdrawn</th>
<th>Date Of Withdrawl</th>
<th>Upload By</th>
<th>Notify<input type="checkbox" onclick="check();" id="select_all" name="select_all" /></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($data as $value) {
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $value['school_name']; ?></td>
<td><?php echo $value['doa']; ?></td>
<td><?php echo $value['register_serial']; ?></td>
<td><a href='<?php echo base_url('signin/editstudent').'/'.$value['id']; ?>'><?php echo $value['name']; ?></a></td>
<td><?php echo $value['dob']; ?></td>
<td><?php echo $value['father_name']; ?></td>
<td><?php echo $value['phone']; ?></td>
<td><?php echo $value['email_address']; ?></td>
</tr>
<?php
$i++;
} ?>
<div class="clearfix pt-md">
</div>
</tbody>
</table>
</form>
</div>
<div class="panel-footer"></div>
</div>
</div>
</div>
</div>
<?php include('layout/footer.php'); ?>
As someone already mentioned:
paginate
filter
'using select star', dont use the star selector if you wont use all the fields.
codeignitter is using Active Record, something that uses DataMapper could be faster, not sure if you can change that though, most probably you can (havent use codeignitter). or using pure php pdo to deal with db.
have a look on how to use generators, they're much faster for processing big sets as they dont load everything in memory at once (that's what foreach would do)
not sure which version of php you're running, but if you're working on php <5.6 then you should definitely upgrade as new versions use much less memory/cpu for dealing with db.
install sql profiler to check if your queries are optimal.

how to pass values between tabs in a html page using php

how can I pass values/ variables between tabs in html using php
I have 3 tabs those are fetched from database. each tab has separate id.
<div class="tab-nav">
<?php while ($row1 = mysql_fetch_array($result1)) : ?>
<?php $row1['name']; ?>
<?php endwhile ?>
</div>
tabs
<div class="tab-holder">
<div class="tab">
<table class="table table-striped">
<thead>
<tr>
<th width="34%">Job Title</th>
<th width="15%">Experience</th>
<th width="29%">Location</th>
<th width="8%">Salary</th>
<th width="7%"></th>
</tr>
</thead>
<tbody>
<?php
while($row = mysql_fetch_array($result)) {
$cat = $row['cat'];
if ($cat =='6') {
$jobtitle = $row['vVacjobtitle'];
?>
<tr>
<td>
<span class="pill medium green"><?php echo $row['vVacjobtitle'] ?></span>
</td>
<td><?php echo $row['experience'] ?></td>
<td><?php echo $row['vVacLocation'] ?></td>
<td><?php echo $row['salary'] ?></td>
<td>
Apply
</td>
</tr>
<?php
}
} ?>
</tbody>
</table>
</div>
how can i get id when clicking the tab
if ($cat == 6)
i want to place id in the place of 6
Thanks in advance .. :)
Since you're passing the value of id as a GET parameter, so you can access it by $_GET['id'] in your PHP code

Database info not showing from my loop

I new to php and learning and need some advice on shoing my database info within a loop which includes html, My page is blank so am wondering why my php isnt valid:
<?php include 'incudes/connect_db.php'; ?>
<div class="topbar">
<div class="topbarblock1">Dashboard</div>
<div class="topbarblock2">Username</div>
</div>
<br><br>
<div class="middle">
<div class="middleblock1">Dashboard</div>
<div class="middleblock2">
<div class="container">
<?php
$result = mysqli_query($con,"SELECT * FROM users");
while($row = mysqli_fetch_array($result)) {
?>
<h2>
User Management
<hr />
</h2>
</div>
<div class="containermain">
<table>
<tr>
<th class="th1">User Id</th>
<th class="th2">Username</th>
<th class="th3">Email Address</th>
<th class="th4">Details</th>
</tr>
<tr>
<td class="td1">#</td>
<td class="td2"><?php echo $row['username']; ?></td>
<td class="td3"><?php $row['email']; ?></td>
<th class="td4">Edit</th>
</tr>
</table>
</div>
</div>
</div>
<?php
}
?>
I'm not looking for a straight out answer I am looking for some advice on how this should be laid out and learn best practices.
Change the line that says
<td class="td3"><?php $row['email']; ?></td>
to
<td class="td3"><?php echo $row['email']; ?></td>
PHP will try to interpret the variable as some sort of command/statement otherwise and subsequently fail.
Also rethink where you wrap the loop as I previously mentioned, or else your HTML is going to end up wonky (you'll see this after you've fixed the code.)
You should also program by using error_reporting(E_ALL); at the start of your code so you can fix simple mistakes on your own

PHP: Form echo's id in source but shows first id in link for all rows

I'm having an issue with a pop up form that has a field where the user needs to enter some info regarding a row of data.
The stuff he/she enters needs to be inserted into the table which I will do a Update query... But my issue is that the form echo's the id from the database in the source code but it doesn't show when I hover over the button.
After I press the button it only executes the query for the first id. And the others show only the 2nd and so forth until they are removed one by one. I don't know what I'm doing wrong:
<?php include_once('classes/profile.class.php');?>
<?php include_once('header.php');?>
<h1>
<?php _e('Traffic Fines Adjudication'); ?>
</h1>
<br>
<div class="tabs-left">
<?php
$result = "SELECT * FROM login_fines_adjudicated WHERE active = 0 ORDER BY date_issued";
$stmt = $generic->query($result);
//this function will take the above query and create an array
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
//do nothing
//with the array created above, I can create variables (left) with the outputted array (right)
$id = $row['id'];
$date = $row['date_added_db'];
$date_issued = $row['date_issued'];
$time_arrive = $row['time_arrived'];
$time_depart = $row['time_departed'];
$ref = $row['reference_code'];
$reason = $row['violation_reason'];
$location = $row['location'];
$bay = $row['bay_number'];
$licence = $row['licence'];
$punit = $row['parking_unit'];
$value = $row['value'];
$operator = $row['operator'];
$operator_id = $row['operator_id'];
//If date field is empty display nothing! Or sentence...
if(!empty($date))
{
?>
<table class="table">
<thead>
<tr>
<th>Photo</th>
<th>Date Added</th>
<th>Date Issued</th>
<th>Time Arrived</th>
<th>Time Departed</th>
<th>Reference Code</th>
<th>Violation Category</th>
<th>Location</th>
<th>Bay Number</th>
<th>Licence Plate</th>
<th>Parking Unit</th>
<th>Amount</th>
<th>Operator Name</th>
<th>Operator ID</th>
<th>Action</th>
</tr>
</thead>
<tr>
<td><img class="photo" src="photos/no-available.jpg" /></td>
<td><?php echo $date; ?><br /></td>
<td><?php echo $date_issued; ?></td>
<td><?php echo $time_arrive; ?></td>
<td><?php echo $time_depart; ?></td>
<td><?php echo $ref; ?></td>
<td><?php echo $reason; ?></td>
<td><?php echo $location; ?></td>
<td><?php echo $bay; ?></td>
<td><?php echo $licence; ?></td>
<td><?php echo $punit; ?></td>
<td><?php echo $value; ?></td>
<td><?php echo $operator; ?></td>
<td><?php echo $operator_id; ?></td>
<td>
<form action="approve.php" method="post">
<input type="hidden" name="delete_id" value="<?php echo $row['id']; ?>" />
<p>Approve</button></p>
</form>
<div id="reject-form" class="modal hide fade">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><?php _e('Reject Reason'); ?></h3>
</div>
<div class="modal-body">
<div id="message"></div>
<form action="reject.php" method="post" name="rejectform" id="rejectform" class="form-stacked rejectform normal-label">
<div class="controlgroup rejectcenter">
<div class="control">
<input id="reject" name="reject" type="text"/>
</div>
</div>
<input type="hidden" name="delete_id" value="<?php echo $id; ?>" />
</form>
</div>
<div class="modal-footer">
<?php _e('Submit'); ?></button>
<p class="pull-left"><?php _e('Please give a short reason for rejecting.'); ?></p>
</div>
</div>
</form>
<p><a data-toggle="modal" href="#reject-form" id="rejectlink" tabindex=-1><button url="#" class="btn btn-primary">Reject</button></a></p>
</td>
</tr>
</table>
<?php
}
}
?>
</div>
<?php include ('footer.php'); ?>
Any help would be appreciated!
The problem is that you have many elements with the same id attribute. Genarally, it is a really bad practice to have more than elements with the same id, not to mention it does not conform to the HTML Spec, according to which "id = [...] This name must be unique in a document.". Therefore, you are strongly advised to fix all IDs mking sure it is unique (e.g. appending the current entry's ID).
What causes the specific problem you described in your question is this:
You define for every table a pop-up dialog (div), with id reject-form.
Then, you implement the "reject"-button as a link with href="#reject-form".
So, when you click on any "reject"-button, the user is taken to the first element found in the DOM with id="reject-form" (which is always the dialog for the first entry).
In order to fix that, you can append each entry's ID in the id attributes in two locations: the pop-up dialog and the "reject"-button:
// Replace that:
<div id="reject-form" class="modal hide fade">
// with this:
<div id="reject-form-<?php echo $id; ?>" class="modal hide fade">
// Replace that:
<a data-toggle="modal" href="#reject-form" id="rejectlink" tabindex=-1>
// with this:
<a data-toggle="modal" href="#reject-form-<?php echo $id; ?>" id="rejectlink" tabindex=-1>

Categories