Right now my array displays information that I need, but I am trying to allow users to claim the jobs by clicking the "claim button" and posting their username, user id, order id, and setting the claimed info to show it is claimed.
<h3>Current Jobs</h3>
<p class="text-muted m-b-20">These are the jobs either in progress or are available to be claimed.</p>
<div class="table-responsive">
<? echo "<table class=\"table table-striped\">
<thead>
<tr>
<tr>
<th>Order #</th>
<th>Order Type</th>
<th>Order ID Number</th>
<th>Order Status</th>
<th>Order Dates</th>
<th>Order Claimed</th>
<th>Claim Job</th>
</tr>
</thead>
<tbody>";
$order_id = $row['order_item_id'];
$user_id = $uid;
$user_name = $username;
while($row = mysql_fetch_array($wclaim))
{
echo "<tr id=" . $row['order_item_id'] . ">";
echo "<td >" . $row['order_item_id'] . "</td>";
echo "<td>" . $row['order_item_name'] . "</td>";
echo "<td>" . $row['order_id'] . "</td>";
echo "<td>" . $row['post_status'] . "</td>";
echo "<td>" . $row['post_date'] . "</td>";
echo('<td>'.(($row['claim_aktiv']==1) ? 'Yes' : 'No').'</td>');
---> if(isset($_POST["submit"])) {
"INSERT INTO claimsystem (claim_id, user_id, user_name, claim_aktiv)
VALUES ('$order_id','$user_id','$user_name','1')";
}
---> echo "<td><input type=\"submit\" name=\"submit\"></input></td>";
echo "</tr>";
}
echo "</tbody></table>";
?>
The code I need help with has a arrow in front of it
--->
When I click on the submit button it does not do anything.
Since the only information you need from the user is an identifier for the given row, you can build a simple small form into each row. Structurally it would look something like this:
while($row = mysql_fetch_array($wclaim))
{
// output your table cells
echo "<td><form method=\"post\"><input type=\"hidden\" name=\"order_item_id\" value=\"" . $row['order_item_id'] . "\" /><input type=\"submit\" name=\"submit\"></input></form></td>";
}
Note the things in that table cell:
form - Each row would have its own small form, so you're only posting just that one row's value when clicking the button.
input type="hidden" - The order_item_id value to be submitted.
input type="submit" - the submit button
You can add an action to the form to post to another page, or post back to this same page by default. When handling the post, you'd just use the value being sent from the input type="hidden":
$_POST["order_item_id"]
That would be the identifier you need to insert the record.
Related
I have created a table and am pulling data from mySQL database. I have created 3 columns and would like to take the 3rd column (suggested quantity) and copy those values into a row of text boxes in the 4th column, (order quantity) so they could be edited by a user. How do I do this?
$sql = "SELECT item_price.item_id, item_price.ITEM_NAME,suggested_qty,Price_item
FROM item_price JOIN suggested_item
ON item_price.ITEM_NAME = suggested_item.ITEM_NAME";
$result = $conn->query($sql);
?>
<tr>
<th> ID</th>
<th>Item Name</th>
<th>Suggested Quantity</th>
<th>Order Quantity</th>
<th>Total Cost ($)</th>
</tr>
<?php
while ($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['item_id'] ."</td>";
echo "<td>" . $row['ITEM_NAME'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
}
?>
</table>
You should start by wrapping the table in a form and add a column with a input text field with the suggested quantity. Something like this should get you started:
$sql = "SELECT item_price.item_id, item_price.ITEM_NAME,suggested_qty,Price_item
FROM item_price JOIN suggested_item
ON item_price.ITEM_NAME = suggested_item.ITEM_NAME";
$result = $conn->query($sql);
?>
<form action="#" method="post">
<table>
<tr>
<th> ID</th>
<th>Item Name</th>
<th>Suggested Quantity</th>
<th>Order Quantity</th>
<th>Total Cost ($)</th>
</tr>
<?php
while ($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['item_id'] ."</td>";
echo "<td>" . $row['ITEM_NAME'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
echo "<td><input type='text' name='editedvalues[]' value='" . $row['suggested_qty'] . "' /></td>";
echo "<td>total</td>";
echo "</tr>";
}
?>
</table>
</form>
You should add a javascript onchange listener to the input fields to calculate a total price for each row and show it to the user.
I have a table with each row having a cancel link. I would like to cancel a booking for the specific rows. May I know how to start?
The codes of the table is as below.
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
echo "<table border = 1>
<tr>
<th>Custid</th>
<th>Venue</th>
<th>Firt Name</th>
<th>Date</th>
<th>Time</th>
<th>Menu Type </th>
<th>No.of table </th>
<th>Total price </th>
<th>Amount Paid </th>
<th>Make Payment </th>
<th>Cancel Booking</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['Customer_id']. " </td>";
echo "<td>" . $row['Venue_name']. " </td>";
echo "<td>" . $row['First_name']. "</td>";
echo "<td>" . $row['Date']. "</td>";
echo "<td>" . $row['Time']. "</td>";
echo "<td>" . $row['Menu_type']. "</td>";
echo "<td>" . $row['no_of_table']. "</td>";
echo "<td>" . $row['total_price']. "</td>";
echo "<td>" . $row['total_amt_paid']. "</td>";
echo"<td><a href='Payment.php'>Payment</a></td>";
echo"<td><a href='Cancel.php'>Cancel</a></td>";
echo "</tr>";
}
echo "</table>";
}
You need to pass the Cancel.php script some knowledge of what it should delete, so change
echo "<td><a href='Cancel.php'>Cancel</a></td>";
to
echo '<td>Payment</td>';
And then in the Cancel.php script you should receive that value in the $_GET array
<?php
$Customer_id = $_GET['Customer_id'];
If you want to cancel a specific booking you'll need something specific about each booking, like a booking id for example. If we assume you already have that in your table then you can pass this unique value (specific to the row) to your cancel.php and payment.php pages.
To do this we will use a get request and a query string. This will mean your original line changes from this:
echo "<td><a href='Cancel.php'>Cancel</a></td>";
to this one below. We can add the query string unique to each row like this: (assuming it might be called booking_id)
echo "<td><a href='Cancel.php?booking_id=".$row['booking_id']."'>Cancel</a></td>";
You can now retrieve this value on the Cancel.php page like this:
$booking_id = $_GET['booking_id'];
It's worth reading up about SQL injection and consider adding some cleaning method for your string to avoid this. If you are a little rusty on GET and POST then you can check this explanation out.
I have echoed my database table onto my website and have tick option next to the table where you can tick it and delete any of the entries from the website, it should delete it from the database. For some reason its not working, I'm a beginner and any help would be greatly appreciated thanks.
<form method="" action="tester.php">
<?php
include 'connect_to_mysql.php';
$count=mysql_num_rows($result);
$result = mysql_query("SELECT * FROM booking ORDER BY ID ASC");
echo "<table border='1'>
<tr>
<th>DEL</th>
<th>Name</th>
<th>Email ID</th>
<th>Phone Number</th>
<th>Collection Address</th>
<th>Collection Date</th>
<th>Collection Time</th>
<th>Make & Model</th>
<th>Message</th>
</tr>";
while($row = mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF"><input name="delete_these[]" type="checkbox" id="checkbox[]" value="<?php echo $row['ID']; ?>"></td>
<?php
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['phonenumber'] . "</td>";
echo "<td>" . $row['collectionaddress'] . "</td>";
echo "<td>" . $row['collectiondate'] . "</td>";
echo "<td>" . $row['collectiontime'] . "</td>";
echo "<td>" . $row['makemodel'] . "</td>";
echo "<td>" . $row['message'] . "</td>";
echo "</tr>";
}
echo "</table>";
?> <br>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
if(isset($_GET['delete'])) {
for($i=0;$i<$count;$i++){
$id = $checkbox[$i];
print_r($_GET['delete_these']);
$ids = implode(', ', $_POST['delete_these']);
$sql = "DELETE FROM booking WHERE id IN($ids)";
echo "<br />SQL: $sql<br />";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
}
}
mysql_close();
?>
</form>
you have add method in your form tag--
<form method="post" action="tester.php" >
and also replace if(isset($_GET['delete'])) to if(isset($_POST['delete']))
Replace your form tag by:
<form method="post" action="tester.php">
then these 3:
if(isset($_POST['delete']))
$id =(int)$_POST['delete_these'][$i];
$sql = "DELETE FROM booking WHERE id=$id";
at the place of these 3:
if(isset($_GET['delete']))
$id = $checkbox[$i];
$sql = "DELETE FROM booking WHERE id IN($ids)";
Your $id = $checkbox[$i]; works only if register_globals directive is on, which is now deprecated (and removed as of PHP 5.4) because of security issues it causes, and if it exists in the version of PHP you are using most hosting services turn it off.
You'll be sending the data through post so you access them through $_POST. the (int) before the $_POST is to cast anything to integer so if the user try to send a string it will become 0, this will protect you from sql injection.
SIDE NOTE you should stop using mysql_* functions as they are deprecated. Check out PDO or mysqli
I'm not entirely sure I'm even asking this correctly. I have a lack of terminology, and I apologize for that up front. You see, I have two php scripts, and I'm trying to learn how php and MySQL work together. In my first php script, order.php, I pull information from my database and display it on the page. Under each item that is pulled, there is a "more info" button. My goal is to have a user click on "more info" for any particular item, and when they do, be redirected to a new page that lists THAT items information.
So far, I have the "more info" button linking to a moreinfo.php script, and it is retrieving THAT items description using urlencode, and displaying it on moreinfo.php.
What I need, is to have the "more info" button on "order.php" pull THAT items description, name, and price.
I've tried adding:
. urlencode($row['description']) . urlencode($row['price']) .
to the code below, and it pulls in the information, but I can't separate it. Here is my code for everything so far.
require("database.php"); //connect to the database
$start = (isset($_GET['start']) ? (int)$_GET['start'] : 0); //setting the get function to a variable so I can display data on same page
$result = mysqli_query($con,"SELECT * FROM menuitem LIMIT $start, 3");
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
echo "<table width='1024' border='0' cellpadding='10' cellspacing='5' align='center'>
<tr align='center'>
<th></th>
<th>Menu Items</th>
<th>Description</th>
<th>Price</th>
<th>Add to Order</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'><img height='100' width='100' src=\"" . $row['picturepath'] . "\" /></td>";
echo '<td align="center">' . $row['name'] . '</td>';
/*echo '<td align="center"><input type="button" value="More Info" onclick="window.location=\'more_info.php?start=' . urlencode($row['description']) .' \';" /></td>';*/
echo '<td align="center"><input type="button" value="More Info" onclick="window.location=\'more_info.php?start=' . urlencode($row['description']) . urlencode($row['price']) .' \';" /></td>';
echo "<td align='center'>" . $row['price'] . "</td> <td align='center'> <input type='button' value='Add to Order' onclick=''> </td>";
echo "</tr>";
}
echo "</table>";
Currently, it is pulling the description and price together, and I have no idea how to separate into different tables. If anyone can even give me a keyword to google, I would gladly look up the info on my own, or do whatever I can to research it to get it working.
Here is the moreinfo.php
$start = (!empty($_GET['start']) ? $_GET['start'] : false);
<html><table width='100%' border='0'><tr><td height="200"></td></tr></table></html>
<?php
echo "<table width='90%' border='0' cellpadding='10' cellspacing='5' align='center'>"
echo "<tr align='center'>
<td width='60%' align='left'>" . $start . "</td>
<td width='40%' align='left'>" "</td>
</tr>";
echo "</table>";
?>
Look at how other sites do the same thing. IE StackOverflow. On the main page, there is a list of questions. When you click a question, that question appears and all data associated with it.
The link to this particular question is http://stackoverflow.com/questions/20622290.
The number at the end of the URL is this questions ID in the database, or some numerical representation of this question anyways.
I would suggest adding the ID of your item to the end of your URLs. IE, http://example.com/moreinfo.php?id=5.
Where 5 is the ID of that item you want to see. This will allow you to grab that items information from the database and you will be able to display it.
So I'm having trouble figuring out how to show a link to a new page based on ID. I've created a review page of all timecards submitted based on employee. It works fine, but in case the employee wants to review an individual record and change specific things in the record is where i'm having trouble with. Below is a snippit of code i'm using to display the information. Because the timecard has MANY fields in I don't need to waste the whole page showing all the information until the employee actually submits the specific card he wants.
$result = mysql_query("SELECT ID,employee,date FROM tcardsubmit WHERE employee = '$empname");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>EMPLOYEE NAME</th>
<th>DATE</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['employee'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
That query shows all I really need the employee to see. What i'd like is for the ID number to carry over to a page called 'review.php' but the ID number carries over with it, then I can just use GET ID and pull all the data based on the ID on the review page. Any suggestions?
make a little change on your table
echo "<table border='1'>
<tr>
<th>ID</th>
<th>EMPLOYEE NAME</th>
<th>DATE</th>
<th>ACTION</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['employee'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>Review</td>";
echo "</tr>";
}
echo "</table>";
In the loop add another column and do
echo '<td>View</td>';
In review.php
$id = (int) $_GET['id'];
And query..
SELECT <fields> FROM tcardsubmit WHERE ID = $id
Make sure to escape id .. I did it by casting to an int, but you can also do mysql_real_escape_string