I've already searching about my problem for 2 days, but nothings happen.
I need your help to fix my problem in editing a data using mysql and php
prod_list.php
<?php
$result = mysql_query("SELECT * FROM product ORDER BY prod_id DESC");
while($row = mysql_fetch_array($result)) {
$image = $row['7'];
?>
<tr>
<td><?php echo $row["0"]; ?></td>
<td><?php echo $row["1"]; ?></td>
<td><?php echo $row["2"]; ?></td>
<td><?php echo $row["3"]; ?></td>
<td><?php echo $row["4"]; ?></td>
<td><?php echo $row["5"]; ?></td>
<td><?php echo $row["6"]; ?></td>
<td> <img src="\sns/uploads/<?php echo $image; ?>" width="30" height="25"></td>
<td><?php echo $row["8"]; ?></td>
<td><?php echo "<a href='index.php?page=9adnk3b8nc&prodid={$row['0']}' class='btn btn-info btn-fill btn-sm pull-right'>Edit</a>"; ?></td>
</tr>
<?php } ?>
When I click the edit. nothing shows up. this is my edit form ..i tried some other edit codes but all of these comes up an error : Undefined variable "prod_id" .
edit_product.php
<div class="content">
<?
$prod_id=$_GET["prod_id"];
$query="select * from product where prod_id='$prod_id'";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<?php
if(isset($_POST['submit']))
{
}
?>
</div>
<div class="col-md-8">
<div class="form-group">
<label>Product ID</label>
<input type="hidden" class="form-control" name="id" autocomplete="off" placeholder="Product Name" value="<?php echo $row['prod_id']; ?>">
</div>
</div>
Its because of variable mismatch.
The Edit link has parameter prodid and in edit_product.php it is $_GET["prod_id"]
Change $_GET["prod_id"] to $_GET["prodid"] and it should work.
Change
index.php?page=9adnk3b8nc&prodid={$row['0']}'
to
index.php?page=9adnk3b8nc&prod_id={$row['0']}'
Related
<?php
while($row = mysqli_fetch_array($results)){
?>
<tbody>
<tr>
<td> <?php echo $row['Product_ID'] ?></td>
<td> <?php echo $row['Product_Name'] ?></td>
<td> <?php echo $row['Product_Price'] ?></td>
<td> <?php echo $row['Product_Stock'] ?></td>
<td> <button type="submit" name="add" id="<?php $row['Product_ID'] ?>" onclick="func(<?php $row['Product_ID'] ?>)"> Add </button></td>
</tr>
<?php } ?>`
<script type="text/javascript" method="post">
function func(id){
window.alert(id);
};
</script>
Is there a way I could store id of my button named add?
I've to store multiple product ids and use them in a receipt that would be generated using product ids. the method of the form is POST but I don't know how to get the id
Replace this
func(<?php $row['Product_ID'] ?>)
With This
func(<?php echo $row['Product_ID']; ?>)
Here is the query statement that I have. For some reason it works for another table I have but doesn't work with this table. I checked phpmyadmin to see if I would create an error but there were zero errors.
$Store_ID = filter_input(INPUT_POST,'Store_ID',FILTER_VALIDATE_INT);
//DELETE the Store
$query="DELETE FROM store_location WHERE Store_ID = :Store_ID";
$statement2=$db->prepare($query);
$statement2->bindValue(':Store_ID',$Store_ID);
$statement2->execute();
$statement2->closeCursor();
Here is the table code for the Delete Button
<?php foreach ($stores as $s) : ?>
<tr>
<td><?php echo $s['Store_ID']; ?></td>
<td><?php echo $s['Loc_Street']; ?></td>
<td><?php echo $s['Loc_City']; ?></td>
<td><?php echo $s['Loc_State']; ?></td>
<td><?php echo $s['Rent']; ?></td>
<td><?php echo $s['License']; ?></td>
<td><?php echo $s['Inspect']; ?></td>
<td><form action="stores.php" method="post">
<input type ="hidden" name ="Store_ID" value ="<?php echo $s['Store_ID']; ?>"/>
<input type="button" name="delete" value="Delete"/>
</form></td>
</tr>
<?php endforeach; ?>
</table>
I have file (feeColect.php) which display information by using php, now I want to run (stockreportPDF.php) file after click Export PDF button, its real confuse me that what is wrong with the code while I used the same on previous project
1: this is (feeColect.php) file.
<tr><td><?php echo $list->idnumber; ?></td>
<td><?php echo $list->name; ?></td>
<td><?php echo $list->class; ?></td>
<td><?php echo $list->boarding_fee; ?></td>
<td><?php echo $list->school_fee; ?></td>
<td><?php echo $list->trans_fee; ?></td>
<td><?php echo $balance; ?></td>
<td><?php echo $list->term; ?></td>
<input type="hidden" name="id" id="id" value="<?php echo $list->id; ?>">
<?php $url_PDFstock ="stockreportPDF.php?from_date=$from_date&to_date=$to_date "; ?>
this is button that it suppose to open windowpop after click
<?php echo "<p> <a onclick=\"return windowpop('". $url_PDFstock ."')\">
<input class='btn btn-round btn-orange' type='button' value='Export PDF'></a></p>";?>
I am showing a list of users information. The users are set at different levels (1-5). I only want it to display information for users that are level 1. Here is basically the code.
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<tr>
<td><input name="u[]" type="checkbox" value="<?php echo $rrows['id']; ?>" id="u[]"></td>
<td><?php echo $rrows['date']; ?></td>
<td><?php echo $rrows['user_level']; ?></td>
<td><?php echo $rrows['user_name'];?></td>
<td><?php echo $rrows['user_email']; ?></td>
<td> <span id="approve<?php echo $rrows['id']; ?>">
<?php if(!$rrows['approved']) { echo "Pending"; } else {echo "Active"; }?>
</span> </td>
<td><span id="ban<?php echo $rrows['id']; ?>">
<?php if(!$rrows['banned']) { echo "no"; } else {echo "yes"; }?>
</span>
</td>
</tr>
How would I say to display only information of users who's 'user_level' = '1'?
You could filter in two ways:
directly in the query, as indicated by #Fred
after fetching the recordset:
while ($rrows = mysql_fetch_array($rs_results)){
if ($rrows['user_level'] == 1){
// display as previously
You would need to put an if statement inside your while loop that checks the user level.
//php mysql while
If ($rrows['user_level'] == 1) {?>
//html code
}?>
Try put the row to if block, like in the following code. It's ugly practice. Will be better if You use condition in the mysql query.
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<?if($rrows['user_level']==1){?>
<tr>
<td><input name="u[]" type="checkbox" value="<?php echo $rrows['id']; ?>" id="u[]"></td>
<td><?php echo $rrows['date']; ?></td>
<td><?php echo $rrows['user_level']; ?></td>
<td><?php echo $rrows['user_name'];?></td>
<td><?php echo $rrows['user_email']; ?></td>
<td> <span id="approve<?php echo $rrows['id']; ?>">
<?php if(!$rrows['approved']) { echo "Pending"; } else {echo "Active"; }?>
</span> </td>
<td><span id="ban<?php echo $rrows['id']; ?>">
<?php if(!$rrows['banned']) { echo "no"; } else {echo "yes"; }?>
</span> </td>
</tr>
<?} /*end if*/?>
<?} /*end while*/?>
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>