I need a help to make the submit button inside the while loop work. I design a code that fetch the value from DB and user has to approve or reject the pulled value. So when user click OK, then the DB should be updated with a OK value. I dont know where is the problem is that my OK button doesnt work,
When user click OK, then it should go to approval.php page
<?php
if ($_POST['action'] == 'show'){
$requestCompSql = "SELECT REQUEST_COMPONENT_CUTTING.PROJECT_NAME,
REQUEST_COMPONENT_CUTTING.BASE_PLATE,
REQUEST_COMPONENT_CUTTING.THICKNESS,
REQUEST_COMPONENT_CUTTING.QTY_REQUESTED,
REQUEST_COMPONENT_CUTTING.REQUESTER,
REQUEST_COMPONENT_CUTTING.REQUEST_DATE
FROM REQUEST_COMPONENT_CUTTING
WHERE REQUEST_COMPONENT_CUTTING.BASE_PLATE = '{$_POST["bp"]}'";
$requestCompParse = oci_parse($conn, $requestCompSql);
oci_execute($requestCompParse);
while($row = oci_fetch_assoc($requestCompParse)){
echo "<form action='approval.php'>";
echo "<div class='table-responsive'>";
echo "<table class='table table-bordered'>";
echo '<table cellspacing = "0"';
echo '<thead>';
echo '<tr>
<th>PROJECT</th>
<th>BASEPLATE</th>
<th>THICKNESS</th>
<th>QTY REQUESTED</th>
<th>REQUESTER</th>
<th>REQ. DATE</th>
<th align="center">ACTION</th>
</tr>
</thead>';
echo "<tbody>";
echo "<tr class='warning'><td>$row[PROJECT_NAME]</td>";
echo "<td>$row[BASE_PLATE]</td>";
echo "<td>$row[THICKNESS]</td>";
echo "<td>$row[QTY_REQUESTED]</td>";
echo "<td>$row[REQUESTER]</td>";
echo "<td>$row[REQUEST_DATE]</td>";
echo "<td><input type='button' value='OK' class='btn btn-success'>
<input type='button' value='REJECT' class='btn btn-danger'></td>";
echo "</tr>";
echo "</tbody>";
echo "<table cellspacing = '0'";
echo "</form>";
echo "</div>";
}
}
?>
For a submit button you need to use
<input type="submit" value="OK">
You used
<input type="button" value="OK">
which can be used for javascript execution. Same for the reject button. You could however send the form with javascript (which is not recommended, as some choose to turn of javascript) by using something like this:
<input type="button" value="OK" onClick="document.forms[0].submit()">
The button needs to be of type="submit" and not only of type="button"
echo "<td><input type='submit' value='OK' class='btn btn-success'>
You have some problems in your code. Firstly if you are posting data through form, then there should be method property for the form like:
echo "<form action='approval.php' method='post'>";
Secondly, if you are submitting the form on clicking the button, then the type of button should be submit instead of button.
<input type='submit' value='OK' class='btn btn-success'>
Since you are using type='button' you should add Javascript to submit the form such as onclick='submit();'
Related
i have made a form in php and inside form there is a loop that extracts multiple values from database(img,name,availability,..) for multiple books i have made a table to display those values to user and after displaying these data in table i have made an issue button inside loop so that every book has its issue button.
My problem is that i have to only retrieve id of that book for which user click issue button. i tried storing it in cookie but it send the id of the first book displayed then i tried get method but that results in sending the last book that is displayed on screen id. but i want is that it should send the id of book which is selected by user
display books
echo "<form action='issue.php' method='get'>";
while ($row= mysqli_fetch_array($result)) {
echo "<div id='img_div' style='background-color:#fff;'> ";
echo "<img src='books/".$row['image']."'>";
// echo "</div>";<div id='text'>
$isbn=$row['isbn'];
echo "<input type='hidden' name='isb' value='$isbn' />";
echo " <table>";
echo "<tr><td> NAME</td><td> ".$row['name']."</td></tr>";
echo "<tr><td> AVAILABILITY</td><td> ".$row['availabilty']."</td></tr>";
echo "<tr><td> CATEGORY</td><td> ".$row['category']."</td></tr>";
echo "<tr><td colspan='2'>
<button type='submit' name='issue'>issue</button></td></tr>";
echo "</table>";
echo "</div><br/>";
if (isset($_GET['issue'])) {
# code...
$bookid=$isbn;
setcookie("bid",$bookid);
if(!isset($_COOKIE['bid'])){
echo "COOKIE NOT SET";
}
else{
echo "COOKIE SET SUCCESSFULLY";
}
}
issue.php(in which i want to send id)
if(isset($_GET['issue'])){
$bookid=$_GET['isb'];
$dbser="localhost";
$use="[redacted]";
$pasw="[redacted]";
$db="[redacted]";
$con=mysqli_connect($dbser,$use,$pasw,$db);
mysqli_select_db($con,$db)or die("db not connected");
$userid=$_COOKIE['id'];
$id=$_SESSION['user']['username'];
$query = "select id from user_account where username='$id'";
$result=mysqli_query($con,$query);
$row= mysqli_fetch_assoc($result);
$uid=$row['id'];
echo "$uid";
echo "<br/>";
echo "$bookid";
$query = "INSERT INTO issue (bookid, userid)
VALUES ('$bookid', '$uid')";
mysqli_query($con, $query)or die(mysqli_error($con));
What you need is a way to select a single row then submit that with the form. That can be accomplished by adding a Radio button to your table inside the form. The user will check the radio button for the item they want then click the submit button.
Here is an example of what that code could look like for your page.
display books
<form action='issue.php' method='get'>
while ($row= mysqli_fetch_array($result)) {
$isbn=$row['isbn'];
echo " <table>";
echo "<tr>";
echo "<td><input type=\"radio\" name=\"optradio\" value=\"".$isbn."\"></td>";
echo "<td> NAME</td><td> ".$row['name']."</td>";
echo "<td> AVAILABILITY</td><td> ".$row['availabilty']."</td>";
echo "<td> CATEGORY</td><td> ".$row['category']."</td>";
echo "</tr>";
echo "</table>";
}
echo "<button type='submit' name='issue'>issue</button>";
echo "</form>";
Here is a HTML snippet so you can see what that PHP code would output in HTML. Click "Run snippet code" below to see the preview.
<form action='issue.php' method='get'>
<table>
<tr>
<td><input type="radio" name="optradio" value="1"></td>
<td> NAME</td>
<td> name1</td>
<td> AVAILABILITY</td>
<td> availability1</td>
<td> CATEGORY</td>
<td> category1</td>
</tr>
<tr>
<td><input type="radio" name="optradio" value="2"></td>
<td> NAME</td>
<td> name2</td>
<td> AVAILABILITY</td>
<td> availability2</td>
<td> CATEGORY</td>
<td> category2</td>
</tr>
</table>
<button type='submit' name='issue'>issue</button>
</form>
Then in issue.php you would look for $_GET['optradio'] to get the selected value.
if(isset($_GET['issue'])){
$bookid=$_GET['optradio'];
$dbser="localhost";
...
...
...
I have this delete function in my system but first I need the server needs to know which table he has to delete that is why I am sending a data when the user click the delete button into the server which is the ID of the data I want to delete..first I need to try and get that data being sent by the form but the problem is sending data is not working in my part I tried to echo out the ID just to see if I have a result but it works fine but when I send it to the server it doesn't print anything.. Here is my code where I fetch the scheduleID and the form
if ($strand<>""){
$query1 = mysqli_query($conn,"SELECT * from schedule natural join instructor where day = 'm' and schedule.strand= '$strand' and timeID ='$id' and grade = '$grade' and semester = '$semester'");
}
$row1 = mysqli_fetch_array($query1);
$schedID = $row['scheduleID'];
$id = $row1 ['scheduleID'];
$count=mysqli_num_rows($query1);
if ($count==0)//checking
{
//echo "<td></td>";
}
else
{
//print
echo "<div class='show'>";
echo "<ul>
<li class='options' style='display:inline'>
<span style='float:left;'><a href='sched_edit.php?id=$id1' class='edit' title='Edit'>Edit</a></span>
<span class='action'><a href='#' id='$id1' class='delete' title='Delete'>Remove</a></span>
</li>";
echo "<form class = 'delete' method = 'post' action ='../functions/delete.php'>";
echo "<li class='showme'>";
echo " <input type='hidden' name='delete' value='$id'>";
echo "<button type='submit' name='delete' class='btn btn-danger'>Display Schedule</button>";
echo $row1['subject'];
echo "</li>";
echo "<li class='$displayc'>$row1[strand]";
echo "<li class='$displaym'>$row1[fname], $row1[lname]</li>";
echo "<li class='$displayr'>Room $row1[room]</li>";
echo "</form>";
echo "</ul>";
echo "</div>";
}
?>
</td>
I tried the hidden attribute in some of my forms and it work there but I don't know why it won't in this form, the $id is working also I tried echoing that inside in this page but the data sent is not printing in the server, here's my server
<?php
session_start();
include 'database.php';
if (isset($_POST['delete'])){
$ID = $_POST['delete'];
}
thanks in advance
The problem here is that you have 2 form elements using the same name attribute, so PHP is only keeping the last value, which is not defined.
See both the <input> and the <button> have the same name! The button is last and has no value; that is what is being used by PHP.
<input type='hidden' name='delete' value='$id'>
<button type='submit' name='delete' class='btn btn-danger'>Display Schedule</button>
So you can just remove the name from the button or change it to something other than delete :-)
I would like to send 2 variables on a click of a button
My Code so far is that:
HTML:
<?php
while ($Case=mysql_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$Case['SubmissionID']."</td>";
echo "<td>".$Case['AppID']."</td>";
echo "<td>".getFullNameApp($Case['AppID'])."</td>";
echo "<td>".getCourseName($Case['SubmissionCourseID'])."</td>";
echo "<td>".getDepartmentName($Case['SubmissionCourseID'])."</td>";
echo "<td>".DateFormat($Case['Date'])."</td>";
echo "<td>".$Case['SubmissionStatus']."</td>";
if ($Case['SubmissionStatus'] == 'Draft') {
echo "<form action='ApplicantApplyDetails.php' method='POST'>";
echo "<td><button type='submit' class='btn btn-success btn-xs' name='modifybtn' value='".array($Case['SubmissionID'], $Case['SubmissionCourseID'])."'>Modify</button></td>";
}
else {
echo "<td><button type='submit' class='btn btn-danger btn-xs disabled' disabled='disabled' name='modifybtndis' value=''>Modify</button></td>";
}
echo "</form>";
echo "</tr>";
}
mysql_close();
?>
PHP:
if (isset($_POST['modifybtn'])) {
$SubmissionID =$_POST['modifybtn'][0];
$CourseID = $_POST['modifybtn'][1];
echo $CourseID;
}
And then get those variables for further processing. Is that possible? I've done single ones but no arrays. My code is not working. The problem I think is in the HTML part, but I have no idea how to fix it. Any hints?
To answer your question; You can convert an array to a string:
$value = json_encode([$Case['SubmissionID'], $Case['SubmissionCourseID']]);
echo "<td><button type='submit' class='btn btn-success btn-xs' name='modifybtn' value='".$value."'>Modify</button></td>";
And covert the string back to the array when reading.
var_dump(json_decode($_POST['modifybtn'], true));
However there is also the option to submit a hidden field:
<input type="hidden" name="courseid" value="<?= $Case['SubmissionCourseID']>">
And just use:
var_dump($_POST);
i have some problem in here. I have textbox value inside table, and when i clicked link "Valid", i can pass the textbox value to another page.
This is my textbox code in table
echo "<form name='nomor' role='form' method='get'>";
echo "<input type='text' name='nomortempat' class='form-control input-sm'></input>";
echo "</form>";
This is my button
echo "<td class='center'>";
echo "<a class='btn btn-primary btn-sm' href='validasi.php?idorder=" . $row['id_order'] . "&pilih=" . $_GET['pilih'] . "'>
<i class='fa fa-check-square-o'>Valid</i></a>
echo "</td>";
Maybe someone can give me a solution, Thank you and have a nice day!!
In the page validasi.php add this:
$IDorder = $_GET['idorder'];
$Pilih = $_GET['pilih'];
Now you have two variables on validasi.php called IDorder and Pilih from your form
Or is it the nomortempat you want?
I think you can just add
$nomortempat = $_GET['nomortempat'];
to the validasi page and it should work. If I understand your code it should be sent
EDIT I was wrong, you need to add a sumbmit button to your form.
Add session start at the top of your pages: session_start();.
Then add this to your first page:
$_SESSION["idorder"] = $idorder;
$_SESSION["pilih"] = $pilih;
Then this code to your form:
echo "<form name='nomor' role='form' method='get'>";
echo "<input type='text' name='nomortempat' class='form-control input-sm'></input>";
echo "<input type='submit' name='submit' value='Submit'></input>";
echo "</form>";
Then on validasi page add this:
$nomortempat = $_GET['nomortempat']; // and:
$IDorder = $_SESSION["idorder"];
$Pilih = $_SESSION["pilih"];
Now you have all three values on validasi.php
with GET form, you could try this:
echo "<form name='nomor' action='action.php' role='form' method='get'>";
echo "<input type='text' name='nomortempat' class='form-control input-sm'></input>";
echo "<input type='submit' value='valid'>";
echo "</form>";
and in action.php page, to catch value in textbox name='nomortempat', code is below:
if (isset($_GET['nomortempat'])){
echo $_GET['nomortempat'];
}
Of course, you could add more input fields whenever you want to inside form with different names.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
So I am making this website and i got some data in my database. The data is read automatically with php into a table. Every table row also gets automatically a checkbox. Now I want to check the checkbox and then press delete and it deletes the checked data out of the database. Any ideas how?
Here is my code:
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Username</th>
<th>Paswoord</th>
<th>Delete</th>
</tr>
<?php
while($user = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$user['UserName']."</td>";
echo "<td>".$user['Pass']."</td>";
echo "<td> <input type='checkbox' name='checkbox' value='checked'</td>";
echo "</tr>";
}
?>
</table>
<form method= "POST" action="deleteuser.php">
<input type="submit" name="delete" value="DELETE USERS">
</form>
this is the code in my delete user.php
$checked = $_POST['checkbox'];
if($_POST['checkbox'] == "checked"){
echo "SUCCEEEEEEES";
}
There are couple of things to be aware of;
The syntax and proper way of writing the <form> tags.
Use the <input> fields inside the <form>.
Pass an array of checkbox[] instead of a single checkbox.
Your Code
<form method= "POST" action="deleteuser.php">
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Username</th>
<th>Paswoord</th>
<th>Delete</th>
</tr>
<?php
while($user = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$user['UserName']."</td>";
echo "<td>".$user['Pass']."</td>";
echo "<td> <input type='checkbox' name='checkbox[]' value='checked'</td>";
echo "</tr>";
}
?>
</table>
<input type="submit" name="delete" value="DELETE USERS">
</form>
PHP
Instead of using this;
if($_POST['checkbox'] == "checked"){
echo "SUCCEEEEEEES";
}
?>
Use this;
<?php
foreach($_POST['checkbox'] as $val)
{
echo $val . " this should be deleted";
}
?>
Well this is what I always do :-
Make these changes to your while loop.
<?php
$c=0;
while($user = mysql_fetch_assoc($records)){
$c++
echo "<tr>";
echo "<td>".$user['UserName']."</td>";
echo "<td>".$user['Pass']."</td>";
echo "<td> <input type='checkbox' name='checkbox-$c' value='checked'</td>";
echo "</tr>";
}
echo "<input type='hidden' name='total' value='$c'>";
?>
deleteuser.php (Access all the checkboxes here via a for loop)
<?php
for($i=1;$i<=$_POST['total'];$i++)
{
if($_POST['checkbox-$i'] == "checked")
{
//commands for delete
}
}
?>
Rename the name of the checkbox from checkbox to checkbox[]. Now you get an Array instead a string.
And then set value-attribute to the ID of you row in the table (Primary Key or whatelse you need to delete them)
echo "<td> <input type='checkbox' name='checkbox[]' value='".$user["UserID"]."'</td>";
Now you can iterate them in PHP
foreach ($_POST["checkbox"] as $value){
// ..Delete FROM ... where userID = $value
}