PHP value wont post - php

Hello for some reason job_id will not parse from myjobs.php to payment.php and I really cannot see how.Does anyone know why this may be?Similar files seem to work but for some reason this wont I am thinking maybe because I also have html code on payment.php which i haven't done before?
<?php while($row = mysqli_fetch_array($result)):?>
<tr>
<td><?php echo $row['job_id']; ?></td>
<td><?php echo $row['title'];?></td>
<td><?php echo $row['description'];?></td>
<td><?php if($row['accepted']==1 AND $row['start_escrow']==0):?><form action = "payment.php">
<input type="hidden" value="<?php echo $row['job_id']?>" name="job_id" />
<input type="submit" class="btn btn-xlarge btn-block btn-primary" value ="Start Escrow"></input></input><?php endif; ?></td>
<td><?php if($row['start_escrow']==1):?><form action = "review.php">
<input type="hidden" value="<?php echo $row['job_id']?>" name="job_id" />
<input type="submit" class="btn btn-xlarge btn-block btn-primary" value ="Start Escrow"></input></input><?php endif; ?></td>
</tr>
<?php endwhile;?>
</table>
payment.php
<?php
require 'config.php';
$jobid = $_POST['job_id'];
$query = "UPDATE job SET start_escrow = '1' WHERE job_id = '$jobid''";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
echo "Thank You For Contacting Us <br>";
$conn->close();
?>

Set your method as POST in form.
<form action = "payment.php" method="POST">
<form action = "review.php" method="POST">

Related

How to delete specified row in a database table using post method in php

//Deleting is working. However, I can't delete the specified row in the table. It always deletes the last row. I hope you could help me. Thank you! This is my code for displaying data from database:
<form action="deleteCart.php" method = "post" role="form">
<?php
while ($row = mysqli_fetch_array($result2)) {
?>
<tr style="text-align: center;">
<td> <img src="images/<?php echo $row["ImageProduct1"]; ?>"/>
<td><?php echo $row['NameProduct1']; ?> </td>
<td>#<?php echo $row['OrderID']; ?></td>
<td><?php echo $row['OrderQuantity']; ?></td>
<td><input type="submit" name="cancelOrder" value = "Cancel" ></td>
<td><input type="hidden" name="hiddenID" value="<?php echo $row['OrderID']; ?>"></td>
</tr>
<?php
}
?>
</form>
//This is my code for deleting:
if(isset($_POST['cancelOrder'])){
orderID = $_POST['hiddenID'];
mysqli_query($con, "DELETE FROM OrderTable WHERE OrderID=$_POST[hiddenID];");
header('location: deleteCart.php');
}
Delete only the last record because you submitting form whole table record. you should try this code. it will work fine.
this will submit separate record.
<?php
while ($row = mysqli_fetch_array($result2)) {
?>
<form action="deleteCart.php" method = "post" role="form">
<tr style="text-align: center;">
<td><img src="images/<?php echo $row["ImageProduct1"]; ?>"/>
<td><?php echo $row['NameProduct1']; ?> </td>
<td>#<?php echo $row['OrderID']; ?></td>
<td><?php echo $row['OrderQuantity']; ?></td>
<td>
<input type="hidden" name="hiddenID" value="<?php echo $row['OrderID']; ?>">
<input type="submit" name="cancelOrder" value = "Cancel" >
</td>
</tr>
</form>
<?php
}
?>

$.post is only submitting first row of results in while loo jquery

I have searched in many threads but can't seem to find the answer. I have a form that is being submitted based on a while loop. I have a jquery system which works but only submits the first result regardless of which row I have chosen to delete. I tried changing all the ID's to classes but that still doesn't work. I don't want to have to reload the page.
This is my code:
<script>
function DeleteHomework() {
var studentid = $(".studentid").val();
var <?php echo $classsubjects; ?> = $(".<?php echo $classsubjects; ?>").val();
var datesent = $(".datesent").val();
$.post("deletehomework.php", { studentid: studentid, datesent: datesent, <?php echo "$classsubjects: $classsubjects,"; ?> },
function(data) {
$('#deletehomeworkresult').html(data);
});
}
</script>
<form>
<?php
while ($row = mysqli_fetch_array($gethomeworkdata)) {
$datehomeworksent = $row['timestamp'];
$datehomeworksent123 = $row['timestamp'];
$datehomeworksent = date('d-m-Y', strtotime($datehomeworksent));
$homeworksubject = $row[$classsubjects];
$javadate = str_replace('-', '', $datehomeworksent);
?>
<tr><input type="text" hidden value="<?php echo $studentid; ?>" name="studentid" class="studentid"><input type="text" hidden value="<?php echo $datehomeworksent123; ?>" name="datesent" class="datesent">
<td><?php echo $datehomeworksent; ?></td>
<td><input type="text" class="form-control <?php echo $classsubjects; ?>" value="<?php echo $homeworksubject; ?>" name="<?php echo $classsubjects; ?>" id="<?php echo $classsubjects; ?>"></td>
<td>
<button type="button" rel="tooltip" class="btn btn-success" onclick="EditHomework();">
<i class="material-icons">edit</i>
</button>
<button type="button" rel="tooltip" class="btn btn-danger" onclick="DeleteHomework();">
<i class="material-icons">close</i>
</button>
</td>
</tr>
<?php
}?> </form>
Would appreciate any help knowing where i've gone wrong.

Saving select option value into database for all rows at once

I have this problem of saving the option value into the database. Everything seems to look correctly but when submitted, the value in the database does not change. The form is in a table which retrieve user's submission and consent_id was use to update the option the admin. Hope anyone can spot what I am missing or what it should be written. Thanks.
This is my code:
manageLeave.php
<script type="text/javascript">
$(document).ready(function () {
$("#confirmForm").click(function () {
$("#statusForm").submit();
});
});
</script>
<body>
...
<tr>
<td><?php echo $staffName; ?></td>
<td><?php echo $convertDateFrom; ?></td>
<td><?php echo $convertDateTo; ?></td>
<td><?php echo $reason; ?></td>
<td>
<form method="post" action="doManageLeave.php" id="statusForm" name="statusForm">
<input type="hidden" name="consentId" value="<?php echo $consentId; ?>">
<select name="leaveStatus" data-native-menu="false">
<option value="" disabled selected style="display: none">Please select one...</option>
<option value="1">Approved</option>
<option value="2">Rejected</option>
</select>
</form>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
}
?>
<input type="button" id="confirmForm" value="Submit" />
</body>
doManageLeave.php
$getConsentId = $_POST['consentId'];
$leaveStatus = $_POST['leaveStatus'];
$editQuery = "UPDATE consent SET approval_id = '$leaveStatus' WHERE consent_id = $getConsentId";
$successInsert = mysqli_query($link, $editQuery) or die ("Error Query ". mysqli_error($link));
mysqli_close($link);

PHP submit form not working

Below is a piece of the code that input the results of a query into radio buttons. Then, when the user pushes one of the buttons in the form, it moves to the pages test.php. I have run into a problem though that the second code (which is on test.php) doesn't seem to work although I can't see any reason that it shouldn't. Any ideas are awesome. Thanks.
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><input type="radio" name="server" value="<?php echo $row['serverId']; ?>" /></td>
<td><?php echo $row['userName']; ?></td>
<td><?php echo $row['dateCreated']; ?></td>
<td><?php echo $row['serverName']; ?></td>
<td><?php echo $row['serverId']; ?></td>
<td><?php echo $row['publicDNS'] ?></td>
<td><?php echo $row['isRunning']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<br>
<?php endif; ?>
<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="server_stop" value="Stop Server"/>
<input type="submit" name="server_terminate" value="Terminate Server"/>
</form>
</body>
</html>
Second Code:
<?php
if (isset($_POST['server_stop'])) {
echo "Server Stopped";
}
if (isset($_POST['server_terminate'])) {
echo "Server Terminated"
}
?>
$_POST['submit'] has to be $_POST['server_stop']
<?php
if (isset($_POST['server_stop'])) {
echo "Server Stopped";
}
if (isset($_POST['server_terminate'])) {
echo "Server Terminated";
}
?>
Your code:
<?php
if (isset($_POST['server_stop'])) {
echo "Server Stopped";
}
if (isset($_POST['server_terminate'])) {
echo "Server Terminated"
}
?>
Both of these conditions are true on form submit. If you want to differentiate between which submit button was pressed, you'll need to make a hidden input and use some javascript:
<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="server_stop" value="Stop Server" onclick="whatwasclicked(this);" />
<input type="submit" name="server_terminate" value="Terminate Server" onclick="whatwasclicked(this);" />
<input type="hidden" name="clicked" id="clicked" />
</form>
Your javascript will be:
function whatwasclicked(c) {
$("#clicked").val() = c.value;
}
Now on the PHP side, you'll check $_POST['clicked'] and see which button was pressed.
EDIT:
Be aware there is Jquery being used here... so be sure to load that library.
If you don't want to use javascript at all, and you're only going to have those submit buttons in the form, you could also do this:
<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="clicked" value="Stop Server"/>
</form>
<form method="post" name="server_information" id="server_information" action="test.php">
<input type="submit" name="clicked" value="Terminate Server"/>
</form>
Now just check for $_POST['clicked'] and you'll see which button was pressed.
if (isset($_POST['submit'])){
$name =trim($_POST['name']);
if (empty($name)){
echo "please input name";
}
else if (!preg_match("/^[a-zA-Z ]*$/",$name)){
$namerr = "Only letters and white space allowed";
}
}

image button for deleting users from mysql

so I've got a problem
$query = "SELECT * FROM users;";
$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row['fio']; ?></td>
<td><?php echo $row['born_date']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['number']; ?></td>
<td><?php echo $row['work_post']; ?></td>
<td><?php echo $row['inwork_date']; ?></td>
<td><center><form action="delete.php" method="POST"><input type="hidden" name="user_id" value="'.$row['user_id'].'"><input type="Submit" class="deleteButton" value="Delete"></form></center></td>
</tr>
<?php
and in delete.php I have
<?php
if(isset($_POST['Submit'])) {
$query = "DELETE FROM users WHERE user_id='$user_id'";
$result = mysql_query($query) or die(mysql_error());
header("Location: edit.php");
exit;
}
?>
I see list of users - it works! But I can not delete anybody.
You're not correctly inserting the ID due to the fact that the PHP interpreter isn't "active" where you seem to think it is.
As such, change...
<input type="hidden" name="user_id" value="'.$row['user_id'].'">
...to...
<input type="hidden" name="user_id" value="<?php echo $row['user_id']; ?>">
...and all will be well. (It happens to us all occasionally.)
Incidentally, wrapping each delete link in a form is perhaps a bit excessive - is there a reason you don't want to use a "normal" link?
UPDATE
You'll also most likely need to explicitly use the HTTP post variable on your delete page as follows:
$query = "DELETE FROM users WHERE user_id='" . intval($_POST['user_id']) . "'";
<input type="Submit" class="deleteButton" value="Delete">
You need a name on this field to pass your if(isset($_POST['Submit'])) {
<input type="Submit" class="deleteButton" value="Delete" name="Submit">
On a slightly different note, I hope you are doing some sort of check that the user executing the delete call has permissions.

Categories