I have this edit form:
<?php
while($rows=mysql_fetch_array($query)){
$area=$rows['area'];
$dates=$rows['dates'];
$number_of_local_hires=$rows['number_of_local_hires'];
$salary_per_local_hire_per_day=$rows['salary_per_local_hire_per_day'];
$amount=$rows['amount'];
echo "<tr id='addr0'>";
echo "<td>";
echo "<input type='text' name='ca_salary_area[]' placeholder='Area' class='form-control' value='$area' required/>";
echo "</td>";
echo "<td>";
echo "<input type='text' name='ca_salary_date[]' placeholder='Date/s' class='form-control' value='$dates' required/>";
echo "</td>";
echo "<td>";
echo "<input type='text' name='ca_salary_localhires[]' placeholder='Number of Local Hires' class='form-control' value='$number_of_local_hires' required/>";
echo "</td>";
echo "<td>";
echo "<input type='text' name='ca_salary_perday[]' placeholder='Salary Per Local Hire Per Day' class='form-control' value='$salary_per_local_hire_per_day'required/>";
echo "</td>";
echo "<td>";
echo "<input type='text' name='ca_salary_amount[]' placeholder='Amount' class='form-control' value='$amount'/>";
echo "</td>";
echo "</tr>";
}
?>
But I can't update it using this query in my edit_salary.php:
$sql_rows = mysql_query("SELECT *FROM `tblcasalaryformdetails` WHERE casalaryform_id =$id");
$num_rows = mysql_num_rows($sql_rows);
if ($num_rows == count($_POST['ca_salary_area'])){
for($i=0;$i<$num_rows;$i++)
{
$nos_hire = $_POST['ca_salary_localhires'][$i];
$nos_salaray = $_POST['ca_salary_perday'][$i];
$subtotal_salary_amount = $nos_hire * $nos_salaray;
$sql = "UPDATE `tblcasalaryformdetails`
SET area = '". $_POST['ca_salary_area'][$i]."',
dates = ". $_POST['ca_salary_date'][$i].",
number_of_local_hires = ". $_POST['ca_salary_localhires'][$i].",
salary_per_local_hire_per_day = ". $_POST['ca_salary_perday'][$i].",
amount = ". $subtotal_salary_amount."
WHERE casalaryform_id = $id";
mysql_query($sql);
}
}
The result is all the values will be updated same as the last row value. What did I missed? I tried show its index, it looks fine.
Related
I have displayed the values from mysql table along with radio buttons with different values. On submit button it should redirect to next page and display the selected values. My code on first file is as follows :
$query1 = "select * from booking";
$result1 = $connection->query($query1);
echo "<form method='post' action='edit.php'>";
echo "<center>";
echo "<table border='1'>";
$count = 0;
while($row = $result1->fetch_row())
{
echo "<tr>";
echo "<td width=".'10'.">";
$count = $count + 1;
#$sr=$sr+1;
echo "<input type='radio' name='select' value='".$count."' />";
#$row = mysqli_fetch_row($result1);
#echo "<tr>";
echo "<td width=".'10'.">";
$rooms = $row[0];
$srrooms = $rooms;
echo "<input type='text' name='srrooms' value='".$srrooms."' hidden='hidden'>";
#echo $srrooms;
echo $rooms;
echo "</td>";
echo "<td width=".'10'.">";
$no_roomss = $row[1];
$nosrrooms = $no_roomss;
echo "<input type='text' name='nosrrooms' value='".$nosrrooms."' hidden='hidden'>";
echo $no_roomss;
echo "</td>";
echo "<td width=".'10'.">";
$no_dayss = $row[2];
$nodays = $no_dayss;
echo "<input type='text' name='nodays' value='".$nodays."' hidden='hidden'>";
echo $no_dayss;
echo "</td>";
echo "<td width=".'10'.">";
$name = $row[3];
echo $name;
echo "</td>";
echo "</tr>";
#$count++;
}
echo "<input name='count' type='hidden' id='count'>"; // hidden input where counter value will be stored
echo "</table>";
echo "<input type='submit' name='submitRooms' />";
echo "</center>";
echo "</form>";
The javascript code is :
$(function(){
$('input[name="select"]').change(function(){
$('#count').val($("input[name='select']:checked").val());
});
});
edit.php code is :
<?php
if(isset($_POST['submitRooms'])){
#$count = $_POST['count'];
#$srrooms=$_POST['srrooms'.$count];
#$nosrrooms=$_POST['nosrrooms'.$count];
#$nodays=$_POST['nodays'.$count];
echo 'Selected values are: '. $srrooms . $nosrrooms . $nodays;
}
?>
You can use counter for submitting the values of the selected radiobutton's row as:
<?php
$query1 = "select * from booking";
$result1 = $connection->query($query1);
echo "<form method='post' action='edit.php'>";
echo "<center>";
echo "<table border='1'>";
$count = 0; // counter variable
while($row = $result1->fetch_row())
{
echo "<tr>";
echo "<td width=".'10'.">";
echo "<input type='radio' name='select' value='".$count."' />";
echo "<td width=".'10'.">";
$rooms = $row[0];
$srrooms = $rooms;
echo "<input type='hidden' name='srrooms".$count."' value='".$srrooms."' >"; // add counter value to every name of the input fields
echo $rooms;
echo "</td>";
echo "<td width=".'10'.">";
$no_roomss = $row[1];
$nosrrooms = $no_roomss;
echo "<input type='hidden' name='nosrrooms".$count."' value='".$nosrrooms."'>";
echo $no_roomss;
echo "</td>";
echo "<td width=".'10'.">";
$no_dayss = $row[2];
$nodays = $no_dayss;
echo "<input type='hidden' name='nodays".$count."' value='".$nodays."' >";
echo $no_dayss;
echo "</td>";
echo "<td width=".'10'.">";
$name = $row[3];
echo $name;
echo "</td>";
echo "</tr>";
$count++;
}
echo "<input name='count' type='hidden' id='count'>"; // hidden input where counter value will be stored
echo "</table>";
echo "<input type='submit' name='submitRooms' />";
echo "</center>";
echo "</form>";
?>
and then use jquery for saving the active radiobuttons count in the hidden count input field [after the above php code]
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type='text/javascript'>
$(function(){
$('input[name="select"]').change(function(){
$('#count').val($("input[name='select']:checked").val());
});
});
</script>
then on your edit.php fetch the posted data as:
<?php
if(isset($_POST['submitRooms'])){
#$count = $_POST['count'];
#$srrooms = $_POST['srrooms'.$count];
#$nosrrooms = $_POST['nosrrooms'.$count];
#$nodays = $_POST['nodays'.$count];
echo 'Selected values are: '. $srrooms . $nosrrooms . $nodays;
}
?>
You didn't have added the whole form code so please add the above mentioned form code and the reason why your code is not working is that you haven't added the count with the input field names. And their is no use of fetching the posted data with count in the edit.php till you don't have the input fields named with the $count variable
echo "<input type='hidden' name='srrooms".$count."' value='".$srrooms."' >";
My <input> values does not get post to my database when I click the submit button. I am unable to find the error. Please help.
<?php
echo "<form action=Display.php method=post>";
echo "<td>" . $fiberexcel['Engineer9'] ." </td>";
echo "<td>" . $fiberexcel['AM10'] ." </td>";
echo "<td>" . "<input type=date name=A12 value=" . $fiberexcel['Quotation11'] ." </td>";
$A6 = date("Y-m-d");
$ExpectDateQuotation12 = strtotime($ReqDate4."+ 10 weekday");
echo "<td>" . date("Y-m-d",$ExpectDateQuotation12) . "</td>";
$ExpectDateQuotation12 = date("Y-m-d",$ExpectDateQuotation12);
$UpdateQuery = "UPDATE `fiberexcel` SET `ExpectDateQuotation12` =
'$ExpectDateQuotation12' WHERE `fiberexcel`.`SiteID0` = '$A1';";
mysqli_query($conn, $UpdateQuery);
echo "<td>" . "<input type=date name=A14 value=" . $fiberexcel['ApprovalJFSRequest13'] ." </td>";
?>
echo "<td>" . "<input type=hidden name=hidden value=" .$fiberexcel['SiteID0'] ." </td>";
//echo "</tr>";
echo "<td>" . "<input type=submit name=update value=update>". "</td>";
echo "</form>";
This is my update button post function:
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE `fiber`.`fiberexcel` SET Quotation11='$_POST[A12]' , ApprovalJFSRequest13='$_POST[A14]' WHERE `fiberexcel`.`SiteID0`='$_POST[hidden]'";
mysqli_query($conn, $UpdateQuery);
};
Could you please check your HTML output in browser.
I have noticed some issues in your code
-you have missed quotes for every attribute values
ex:
echo "";
wolud be like
echo "";
also there is an error in your HTML code,
ex:
echo "" . "";
here your have missed to close the input tag,
your code wold be like below,
<?php
echo "<form action='Display.php' method='post'>";
echo "<td>" . $fiberexcel['Engineer9'] ." </td>";
echo "<td>" . $fiberexcel['AM10'] ." </td>";
echo "<td>" . "<input type='date' name='A12' value='" . $fiberexcel['Quotation11'] ."'></td>";
$A6 = date("Y-m-d");
$ExpectDateQuotation12 = strtotime($ReqDate4."+ 10 weekday");
echo "<td>" . date("Y-m-d",$ExpectDateQuotation12) . "</td>";
$ExpectDateQuotation12 = date("Y-m-d",$ExpectDateQuotation12);
$UpdateQuery = "UPDATE `fiberexcel` SET `ExpectDateQuotation12` =
'$ExpectDateQuotation12' WHERE `fiberexcel`.`SiteID0` = '$A1';";
mysqli_query($conn, $UpdateQuery);
echo "<td>" . "<input type='date' name='A14' value='" . $fiberexcel['ApprovalJFSRequest13'] ."'> </td>";
echo "<td>" . "<input type='hidden' name='hidden' value='" .$fiberexcel['SiteID0'] ."'> </td>";
//echo "</tr>";
echo "<td>" . "<input type='submit' name='update' value='update'>". "</td>";
echo "</form>";
?>
There is some syntax error in your code. Please check the php close tag and input close tag. Try this..
<?php
echo "<form action='Display.php' method='post'>";
echo "<td>" . $fiberexcel['Engineer9'] ." </td>";
echo "<td>" . $fiberexcel['AM10'] ." </td>";
echo "<td><input type='date' name='A12' value=" . $fiberexcel['Quotation11'] ."/></td>";
$A6 = date("Y-m-d");
$ExpectDateQuotation12 = strtotime($ReqDate4."+ 10 weekday");
echo "<td>" . date("Y-m-d",$ExpectDateQuotation12) . "</td>";
$ExpectDateQuotation12 = date("Y-m-d",$ExpectDateQuotation12);
$UpdateQuery = "UPDATE `fiberexcel` SET `ExpectDateQuotation12` =
'$ExpectDateQuotation12' WHERE `fiberexcel`.`SiteID0` = '$A1';";
mysqli_query($conn, $UpdateQuery);
echo "<td><input type='date' name='A14' value=" . $fiberexcel['ApprovalJFSRequest13'] ." /></td>";
echo "<td><input type='hidden' name='hidden' value=" .$fiberexcel['SiteID0'] ." /></td>";
//echo "</tr>";
echo "<td><input type='submit' name='update' value='update'></td>";
echo "</form>";
?>
There is an error in my php that I cannot solve. Everything is working including 'insert' but not update but I don't know why. If you can help me it would be great. Thank you!
i cannot make update on PHP (Mysqli)
<?php
include("conn.php");
echo "<meta charset='utf-8'>";
?>
<?php
$id = $_GET['edi'];
$showrecs = "SELECT ID, English, Georgian FROM register WHERE ID='$id'";
$result = $conn->query($showrecs);
if(isset($_POST['update'])){
$Updatee = "UPDATE register SET English='".$_POST['English']."', Georgian='".$_POST['Georgian']."' WHERE ID='$id'";
$res=mysqli_query($conn, $Updatee);
if($res==1){
echo "წარმატებით განხორციელდა რედაქტირება.";
echo "<br>";
echo "<a href='view.php'>ჩანაწერების ნახვა</a>";
}
if($res==0){
echo "არაფერიც არ მოხდა";
}
exit();
} elseif ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<form method=POST>";
echo "<tr>";
echo "<td>" . "<input type='text' name='id' value=" . $row['ID'] ." disabled>". "</td>";
echo "<td>" . "<input type='text' name='English' value=" . $row['English'] .">". " </td>";
echo "<td>" . "<input type='text' name='Georgian' value=" . $row['Georgian'] .">". " </td>";
echo "<td>" . "<input type='submit' name='update' value='შეცვლა'>" . " </td>";
echo "</form>";
echo "</br>";
echo "</br>";
}
} else {
echo "Error;";
}
$conn->close();
?>
I'm trying to design a control page for my website that allows admins to delete requests to use a 3D printer at my school. The page displays a query of the schedule from the MySQL database and puts a delete button next to every entry. However, I would like to link the information in each entry to its respective delete button and have no idea how to do that. You can see the page itself here: http://kepler.covenant.edu/~techclub/PHP/manage%20printer%20schedule.php and this is my code for displaying the information
if ($result = $mysqli->query($query)) {
// see if any rows were returned
if ($result->num_rows > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
echo "<tr>";
echo "<th>Control</th>";
echo "<th>Student ID</th>";
echo "<th>Last Name</th>";
echo "<th>First Name</th>";
echo "<th>Date and Time</th>";
echo "<th>Description</th>";
echo "</tr>";
$key = 1;
while($row = $result->fetch_array()) {
echo '<form method="POST" name="deleterequest" action = "delete request.php">';
echo "<tr>";
echo "<td><input name='".$row[5]."'type='submit' value='Delete' ></td>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "<td>".$row[4]."</td>";
echo "</tr>";
echo "</form>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No upcoming prints found!";
}
// free result set memory
$result->close();
}
I can't figure out how to link the information in a row with the delete button that I put in the row to send to the delete request.php program (which I have no code for yet)
you should put hidden field that hold each record id.
As below
while($row = $result->fetch_array()) {
echo "<tr>";
echo "<td>";
echo '<form method="POST" name="deleterequest" action = "delete request.php">';
echo "<input name='recored_id' type='hidden' value='".$row['id']."' >";
echo "<input name='delete'type='submit' value='Delete' >";
echo "</form>";
echo "</td>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "<td>".$row[4]."</td>";
echo "</tr>";
echo "</form>";
}
Now from your request.php page you should do something like this
$recored_id = (int) $_POST['recored_id'];
$sql = "DELETE FROM table_name WHERE recored_id='$recored_id'";
Don't forget to give this code some security validation
all the best,
You're going to need some hidden inputs, like so:
while($row = $result->fetch_array()) {
echo "<tr>";
echo '<td><form method="POST" name="deleterequest" action = "deleterequest.php">';
echo "<input type='hidden' name='val0' value='" . $row[0] . "'>";
echo "<input type='hidden' name='val1' value='" . $row[1] . "'>";
echo "<input type='hidden' name='val2' value='" . $row[2] . "'>";
echo "<input type='hidden' name='val3' value='" . $row[3] . "'>";
echo "<input type='hidden' name='val4' value='" . $row[4] . "'>";
echo "<input name='".$row[5]."'type='submit' value='Delete' >";
echo "</form></td>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "<td>".$row[4]."</td>";
echo "</tr>";
}
You should change the name of these inputs though
The Problem: Trying to calculate sum of a total variable which is inside the table invoicesub in the Form Process (2nd page). Trying to make the sum(total) appear in 3rd page which is display_invoice and also get the customer_name in the form process page(2nd page). somehow $_get["$cust_name"]; is not working and im getting a blank from it. Next, after i can get the sum_total variable how do i parse all these to the 4th page using a form?
Edit:http://imageshack.com/a/img19/8729/btls.png (picture of output)
http://imageshack.com/a/img20/8744/s3ut.png (picture of my database)
Too low rep, i cant post images. I uploaded it to image shack. The 1 on top of the table is from the mysqli_num_rows. This is the first row i entered in the form page. The 2nd row is missing
edit:
New Invoicefinal
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Services Rendered</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Price($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Amount</th>\n";
echo "</tr>";
$cname = $_GET["cname"];
global $connection;
$sql1="SELECT description,quantity, amount, discount, total, SUM(total) as sumtotal FROM invoicesub WHERE cust_name='$cname' GROUP BY description ORDER BY id";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
echo $count;
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['description'] . "</td>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
$sql1="SELECT SUM(total) as total_amt FROM invoicesub WHERE cust_name='$cname'";
$result3 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result3)){
echo "<tr>";
echo "<td>". "Total Amount:" ."$". $rows['total_amt'] . "</td>";
echo "</tr>";
echo "<form action=\"4thpage.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"total_amt\"/>";
echo "Customer Paid:";
echo "<input type=\"text\" name=\"paid\" value=\"\"/>";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\"/>";
echo "<input type=\"button\" value=\"Cancel\" onclick=\"window.location='manage_content.php';\"/>";
echo "</form>";
}
The Form: It consists of a form that can allow more than 1 row of inputs, which means i will have more than 2 descriptions, quantity, amount and discount. Thus, i put them inside an array
Form Process: This is the 2nd page, it will take in all the arrays parsed in, make a loop to insert all the inputted variables in the form into the table invoicesub.
Display_invoice: This is the 3rd page, i want to show all the customer_name, descriptions, quantity, amount, total_amt that was keyed into invoicesub and then do a sum(total) and show it at the bottom of the page. I also want to insert the customer_name, sum(total) variable into the fourth page through the form at display_invoice. Is this possible?
Form
function addTextArea(){
count= count+1;
var div = document.getElementById('name');
div.innerHTML += "<div> <input type='text' name='name[]' value='' "+"id=name"+count+"> </div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('quantity');
div.innerHTML += "<div><input type='text' name='quantity[]' value ='' "+"id=quantity"+count+"></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('amount');
div.innerHTML += "<div><input type='text' name='amount[]' value ='' "+"id=amount"+count+"></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('discount');
div.innerHTML += "<div><input type='text' name='discount[]' value ='' "+"id=discount"+count+"></div>";
div.innerHTML += "\n<br />";
}
function removeTextArea(){
document.getElementById("name"+count).remove();
document.getElementById("quantity"+count).remove();
document.getElementById("amount"+count).remove();
document.getElementById("discount"+count).remove();
count = count-1;
}
</script>
</head>
<body>
<form action="invoiceprocess.php" method="POST">
<?php
echo "<table border='2'>\n";
echo "<tr>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "</tr>";
echo "<tr>";
echo "<td>"?><input type='text' size="50" name='name[]' value='Examination and Consultation' readonly/><?php "</td>";
echo "<td>"?><input type='text' size="50" name='quantity[]' value='' /><?php "</td>";
echo "<td>"?><input type='text' size="50" name='amount[]' value='' /><?php "</td>";
echo "<td>"?><input type='text' size="50" name='discount[]' value='' /><?php "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"?><div id="name"></div> <?php "</td>";
echo "<td>"?><div id="quantity"></div> <?php "</td>";
echo "<td>"?><div id="amount"></div> <?php "</td>";
echo "<td>"?><div id="discount"></div> <?php "</td>";
echo "</tr>";
?>
Customer Name:
<br />
<input type="text" name="cust_name" value="" />
<br />
<input type="button" value="Add Description" onClick="addTextArea();">
<input type="button" value="Remove Description" onClick="removeTextArea();">
<input type="submit" name="submit" value="submit">
</form>
</body>
invoiceprocess (The 2nd page)
if (isset($_POST['submit'])){ // Process the form
$name_array = $_POST['name'];
$quantity_array = $_POST['quantity'];
$amount_array = $_POST['amount'];
$discount_array = $_POST['discount'];
$cust_name_array = mysql_prep( $_POST['cust_name']);
for ($i = 0; $i < count($name_array); $i++){
$cust_name = $cust_name_array;
$name = $name_array[$i];
$quantity = $quantity_array[$i];
$amount = $amount_array[$i];
$discount = $discount_array[$i];
$total_amt = ($amount - ($amount * ($discount / 100))) * $quantity;
global $connection;
$query = "INSERT INTO invoicesub (";
$query.= " cust_name, description, quantity, amount, discount, total";
$query.= ") VALUES (";
$query.= " '{$cust_name}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total_amt}";
$query.= ")";
$result = mysqli_query($connection, $query);
}
redirect_to("invoicesubmitfinal.php?cname=".urlencode($cust_name));
}
Display_Invoice(invoicesubmitfinal.php)
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Customer_name</th>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Total_amt</th>\n";
echo "</tr>";
$cust_name = $_GET["$cust_name"];
global $connection;
$sql1="SELECT SUM(total) FROM invoicesub WHERE cust_name='$cust_name'";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "<td>" . "$" . $total_amt . "</td>";
echo "</tr>";
<form action="insertfinal.php" method="POST">
Customer Paid:
<input type="text" name="paid" value="" />
</form>