I just get this error below. It does work on localhost. Any ideas?
Any advise on how to google this error would help a lot as well, as I am not sure where the problem might be.
"The requested URL /edit.php was not found on this server."
<?php
include ('includes/connection.php');
include ('includes/functions.php');
include ('includes/header.php');
$jobId = $_GET["id"];
$query = "SELECT * FROM Freight, WHERE id = '$jobId'";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$jobArrival = $row["Arrival"];
$jobDeparture = $row["Departure"];
$jobClient = $row["Client"];
$jobAirportOfDeparture = $row["AirportOfDeparture"];
$jobAirportOfArrival = $row["AirportOfArrival"];
$jobAdditionalInfo = $row["AdditionalInfo"];
$jobBoxType = $row["BoxType"];
$jobTemp = $row["Temp"];
// prideti is dezes table
// $pavadinimas = $row["pavadinimas"];
// $likutis = $row["likutis"];
if (isset($_POST['update'])) {
$jobArrival = validateFormData($_POST['jobArrival']);
$jobDeparture = validateFormData($_POST['jobDeparture']);
$jobClient = validateFormData($_POST['jobClient']);
$jobAirportOfDeparture = validateFormData($_POST['jobAirportOfDeparture']);
$jobAirportOfArrival = validateFormData($_POST['jobAirportOfArrival']);
$jobAdditionalInfo = validateFormData($_POST['jobAdditionalInfo']);
$jobBoxType = validateFormData($_POST['jobBoxType']);
$jobTemp = validateFormData($_POST['jobTemp']);
$query = "UPDATE Freight SET Arrival = '$jobArrival',
Departure = '$jobDeparture',
Client = '$jobClient',
AirportOfDeparture = '$jobAirportOfDeparture',
AirportOfArrival = '$jobAirportOfArrival',
AdditionalInfo = '$jobAdditionalInfo',
BoxType = '$jobBoxType',
Temp = '$jobTemp'
WHERE id = '$jobId'";
$result = mysqli_query($connection, $query);
if ($result) {
header("Location: formdisplay.php");
} else {
"Klaida" . mysqli_error($connection);
}
}
}
}
else {
echo "Nera irasu!!!!!!!!!!!!!!";
}
if (isset($_POST['istrinti'])) {
$query = "DELETE FROM Freight WHERE id ='$jobId'";
$result = mysqli_query($connection, $query);
if ($result) {
header("Location: formdisplay.php?alert=deleted");
}
else {
echo "Error" . mysqli_error($connection);
}
}
mysqli_close($connection);
?>
<h1> Iraso koregavimas</h1>
<table>
<tr>
<td>Arrival</td>
<td>Departure</td>
<td>Client</td>
<td>Airport Of Departure</td>
<td>Airport Of Arrival</td>
<td>Additional Info</td>
<td>Box Type</td>
<td>Temp</td>
</tr>
<tr>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?id=<?php echo $jobId; ?>">
<td>
<input type = "text"
value = "<?php echo $jobArrival ?>"
name = "jobArrival">
</td>
<td>
<input type = "text"
value = "<?php echo $jobDeparture ?>"
name = "jobDeparture">
</td>
<td>
<input type = "text"
value = "<?php echo $jobClient ?>"
name = "jobClient">
</td>
<td>
<input type = "text"
value = "<?php echo $jobAirportOfDeparture ?>"
name = "jobAirportOfDeparture">
</td>
<td>
<input type = "text"
value = "<?php echo $jobAirportOfArrival ?>"
name = "jobAirportOfArrival">
</td>
<td>
<input type = "text"
value = "<?php echo $jobAdditionalInfo ?>"
name = "jobAdditionalInfo">
</td>
<td>
<input type = "text"
value = "<?php echo $jobBoxType ?>"
name = "jobBoxType">
</td>
<td>
<input type = "text"
value = "<?php echo $jobTemp ?>"
name = "jobTemp">
</td>
<td>
<input type = "submit"
name = "update"
value = "update"
href = "formdisplay.php"></td>
<td>
<input type ="submit"
name ="istrinti"
value ="istrinti"
href ="formdisplay.php">
</td>
</form>
</tr>
</table>
The key here is likely the / in /edit.php. Try including just edit.php instead, or more directly pathing it to the directory.
Good luck!
Problem SOLVED. Problem on line 143, few wrong spaces.
Took me only a week to find it :)
Code has to look like this <form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?id=<?php echo $jobId ?>">
Related
When I click the borrow button, it should execute my borrowing.php but it just returns to itself. It's not executing the action. Is there some way I can solve this?
<form id = "myform" action="includes/borrowing.php" method = "POST" enctype ="multipart/form-data">
<div class = "form-group pull-left">
<label>Student Name:</label>
<br />
<select name = "fIDNumber" id = "student">
<option value = "" selected = "selected" disabled = "disabled">Select an option</option>
<?php
$qborrow = $con->query("SELECT * FROM `tblstudents` ORDER BY `fLastName`") or die(mysqli_error());
while($fborrow = $qborrow->fetch_array()){
?>
<option value = "<?php echo $fborrow['fIDNumber']?>"><?php echo $fborrow['fFirstName']." ".$fborrow['fMiddleName']." ".$fborrow['fLastName']?></option>
<?php
}
?>
</select>
</div>
<div class = "form-group pull-right">
<button name = "save_borrow" class = "btn btn-primary"><span class = "glyphicon glyphicon-thumbs-up"></span> Borrow</button>
</div>
<table id = "table" class = "table table-bordered">
<thead>
<th>Select</th>
<th> Code </th>
<th> Title </th>
<th> Author </th>
<th> Category </th>
<th> Shelf Location </th>
<th> Edition </th>
</thead>
<tbody>
<?php
$sql = $con->query("SELECT * FROM `tblbooks`") or die(mysqli_error());
while($row = $sql->fetch_array()){
$q_borrow = $con->query("SELECT * FROM `tblbooks` WHERE `fBookCode` = '$row[fBookCode]' and `fStatus` = '$row[fStatus]'") or die(mysqli_error());
$status = $q_borrow->fetch_array();
?>
<tr>
<td>
<?php
if($status == 'Borrowed'){
echo "<center><label class = 'text-danger'>Not Available</label></center>";
}else{
echo '<input type = "hidden" name = "fBookCode[]" value = "'.$row['fBookCode'].'"><center><input type = "checkbox" name = "selector[]" value = "1"></center>';
}
?>
</td>
<td><center> <?php echo $row['fBookCode']; ?> </center></td>
<td> <?php echo $row['fTitle']; ?> </td>
<td> <?php echo $row['fAuthor']; ?> </td>
<td> <?php echo $row['fCategory']; ?> </td>
<td> <?php echo $row['fShelfLocation']; ?> </td>
<td> <?php echo $row['fEdition']; ?> </td>
</tr>
<?php
}
?>
</tbody>
</table>
</form>
Here's my borrowing.php This is not yet fully finished but atleast it should be able to read this. I tried using a link but it won't read my fields anymore. I want to use the form method but it really is not seeing this.
<?php
require_once 'connection_db.php';
if(!ISSET($_POST['fIDNumber'])){
echo '
<script type = "text/javascript">
alert("Select student name first");
window.location = "../borrow.php";
</script>
';
}else{
if(!ISSET($_POST['selector'])){
echo '
<script type = "text/javascript">
alert("Selet a book first!");
window.location = "../borrow.php";
</script>
';
}else{
foreach($_POST['selector'] as $key=>$value){
$fIDNumber = $_POST['fIDNumber'];
$fBookCode = $_POST['fBookCode'][$key];
$date = date("Y-m-d", strtotime("+8 HOURS"));
$conn->query("INSERT INTO `tbltransactions` VALUES('', '$fBookCode', '$fIDNumber', '$book_qty', '$date', 'Borrowed')") or die(mysqli_error());
echo '
<script type = "text/javascript">
alert("Successfully Borrowed");
window.location = "../borrow.php";
</script>
';
}
}
}
Looks like you were trying to access the $row in an incorrect manner. Try this:
$fBookCodeVal = $row['fBookCode'];
$fStatus = $row['fStatus'];
$q_borrow = $con->query("SELECT * FROM `tblbooks` WHERE `fBookCode` = '$fBookCodeVal' and `fStatus` = '$fStatus'") or die(mysqli_error());
Also I noticed that you were not using prepared statements(with binded parameters). It seems as though $row is being populated via a query which of course if a row's fBookCode value contained malicious code then SQL injection could be performed.
Also change:
$status = $q_borrow->fetch_array();
to
$status = $q_borrow->mysqli_fetch_assoc();
and then update:
if($status['status'] == 'Borrowed')
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've been looking for a solution to this problem, but with no luck. Basically when inserting an item in a table it doesn't return a result (doesn't insert anything). I've checked the table fields and all match, I can't seem to find what error I'm doing.
Here's the portion of the code I currently have, where the problem occurs.
<br>
<h3><center><b>Components management</b></center></h3>
<br>
<form name = "registo" method = "POST" action = "">
<center><fieldset>
<legend>Insert component</legend>
<br>
<p><b> Nome: <input type = "text" name = "component_name" required></b> </p><br>
<p> <b>Type:</b> </p>
<div class = "mytable">
<table><tr>
<?php
$queryComp_Type = "select id, name from conc_type order by name";
$resultadoQueryComp_Type = mysqli_query($conn, $queryComp_Type);
foreach ($resultadoQueryComp_Type as $rowComp_Type)
{
?>
<th><?php echo $rowComp_Type['name']; ?></th>
<?php
}
?>
</tr><tr>
<?php
foreach ($resultadoQueryComp_Type as $rowComp_Type)
{
?>
<td><input class= "radio" type= "radio" name= "component_type" value= "<?php echo $rowComp_Type['id']; ?>" required> </td>
<?php
}
?>
</tr></table>
</div><br>
<p> <b>State:</b></p>
<table class="mytable">
<tr><th>Active</th><th>Inactive</th></tr>
<tr>
<td> <input class= "radio" type= "radio" name= "component_state" value= "active" required></td>
<td> <input class= "radio" type= "radio" name= "component_state" value= "inactive"></td>
</tr>
</table>
<br>
<!--Insert button-->
<input type= "hidden" name= "state" value= "inserir">
<input class= "button" type= "submit" value= "Inserir Componente">
<br><br>
</fieldset></center>
</form>
<?php
}
else if($_REQUEST['state'] == "inserir")
{
?>
<h3>Components management - inserçtion</h3>
<?php
$component_name = $_REQUEST['component_name'];
$component_type = $_REQUEST['component_type'];
$component_state = $_REQUEST['component_state'];
$insert = sprintf("INSERT INTO `concept` (`name`,`conc_type_id`,`state`) VALUES ('%s', '$component_type', '%s')", mysqli_real_escape_string($conn, $component_name),
mysqli_real_escape_string($conn, $component_state));
$resultado_insert = mysqli_query($conn, $insert);
if($resultado_insert)
{
mysqli_query($conn,'COMMIT');
?>
<p>Insert successfuly</p>
<p>Click in Continue to advance.</p>
<?php
}
else
{
mysqli_query($conn,'ROLLBACK');
?>
<p>Insertion error.</p>
<?php
}
back();
}
}
?>
If anyone could help I'd be really grateful!
EDIT: Changed $$component_name to $component_name. (Typo)
EDIT: Full page code.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"href="/custom/css/ag.css">
</head>
<body>
<?php
require_once("custom/php/common.php");
if(!is_user_logged_in() && !current_user_can('manage_components'))
{
echo "You don't have permission to access this page";
}
else
{
if($_REQUEST['state'] == "")
{
$verify_component = "SELECT * FROM concept";
$result_component = mysqli_query($conn, $verify_component);
if(mysqli_num_rows($result_component) == 0)
{
echo "Não há componentes";
}
else
{
?>
<table class="mytable">
<thead><tr>
<th>Type</th>
<th>ID</th>
<th>Name</th>
<th>State</th>
<th>Ação</th>
</tr></thead>
<!--<tbody>-->
<?php
$choice_comp_type = "SELECT * FROM conc_type";
$resultado_comp_type = mysqli_query($conn, $choice_comp_type);
while($type = mysqli_fetch_array($resultado_comp_type))
{
$choice_components = "SELECT component.*
FROM concept,conc_type
WHERE conc_type.id = concept.conc_type_id
AND conc_type_id = '".$type['id']."'";
$result_components = mysqli_query($conn, $choice_components);
$num_rows = mysqli_num_rows($result_components);
if($num_rows > 0)
{
?>
<tr>
<td class= "Name" colspan = "1" rowspan = "<?php echo $num_rows; ?>"> <?php echo $type['name']; ?> </td>
<?php
while($row = mysqli_fetch_array($result_components))
{
?>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<?php
if($row['state'] == "active")
{
?>
<td>active</td>
<td>[edit] [desactivate]</td>
<?php
}
else
{
?>
<td>inactive</td>
<td>[edit] [activate]</td>
<?php
}
?>
</tr>
<?php
}
}
}
?>
<!--</tbody>-->
</table>
<?php
}
?>
<br>
<h3><center><b>Management Compontent - introduction</b></center></h3>
<br>
<form name = "registo" method = "POST" action = "">
<center><fieldset>
<legend>Insert component</legend>
<br>
<p><b> Name: <input type = "text" name = "component_name" required></b> </p><br>
<p> <b>Type:</b> </p>
<div class = "mytable">
<table><tr>
<?php
$queryComp_Type = "select id, name from conc_type order by name";
$resultadoQueryComp_Type = mysqli_query($conn, $queryComp_Type);
foreach ($resultadoQueryComp_Type as $rowComp_Type)
{
?>
<th><?php echo $rowComp_Type['name']; ?></th>
<?php
}
?>
</tr><tr>
<?php
foreach ($resultadoQueryComp_Type as $rowComp_Type)
{
?>
<td><input class= "radio" type= "radio" name= "component_type" value= "<?php echo $rowComp_Type['id']; ?>" required> </td>
<?php
}
?>
</tr></table>
</div><br>
<p> <b>State:</b></p>
<table class="mytable">
<tr><th>active</th><th>Inactive</th></tr>
<tr>
<td> <input class= "radio" type= "radio" name= "component_state" value= "active" required></td>
<td> <input class= "radio" type= "radio" name= "component_state" value= "inactive"></td>
</tr>
</table>
<br>
<!--Botão Inserir-->
<input type= "hidden" name= "state" value= "inserir">
<input class= "button" type= "submit" value= "Inserir Componente">
<br><br>
</fieldset></center>
</form>
<?php
}
else if($_REQUEST['state'] == "inserir")
{
?>
<h3>Management component - insertion</h3>
<?php
$component_name = $_REQUEST['component_name'];
$component_type = $_REQUEST['component_type'];
$component_state = $_REQUEST['component_state'];
$insert = sprintf("INSERT INTO `concept` (`name`,`conc_type_id`,`state`) VALUES ('%s', '%s', '%s')", mysqli_real_escape_string($conn, $component_name), mysqli_real_escape_string($conn, $component_type),
mysqli_real_escape_string($conn, $component_state));
$resultado_insert = mysqli_query($conn, $insert);
if($resultado_insert)
{
mysqli_query($conn,'COMMIT');
?>
<p>Successfull insertion</p>
<p>Click in Continue to advance.</p>
<?php
}
else
{
mysqli_query($conn,'ROLLBACK');
?>
<p>Insertion error</p>
<?php
}
back();
}
}
?>
</body>
</html>
First when you create a table... get a result of query... i think should be like this :
<div class = "mytable">
<?php
$queryComp_Type = "select id, name from conc_type order by name";
$resultadoQueryComp_Type = mysqli_query($conn, $queryComp_Type);
$tableHeader = "";
$tableBody = "";
?>
<table>
<thead>
<?php
while ($row = mysqli_fetch_array($resultadoQueryComp_Type)) {
$tableHeader .= '<tr>
<th>'.$row['name'].';</th>
</tr>';
}
?>
<?=$tableHeader?>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($resultadoQueryComp_Type)) {
$tableBody .= '<tr>
<td>'.$row['id'].'</td>
</tr>';
}
?>
<?=$tableBody?>
</tbody>
</table>
</div>
How should I change the code in order to update multiple rows at once, when I click on submit?
This is the code:
<html>
<title></title>
<head>
</head>
<body>
<form action="" method="post">
<table>
<tr>
<td><h6>Seatwork 1</h6></td>
<td><h6>Seatwork 2</h6></td>
<td><h6>Seatwork 3</h6></td>
<td><h6>Quiz 1</h6></td>
<td><h6>Quiz 2</h6></td>
</tr>
<?php
$query1="SELECT * FROM tbl...";
$query = mysql_query($query1) or die(mysql_error());
while($user = mysql_fetch_assoc($query)){
$userid = $user['userid'];
$first = $user['first_name'];
$last = $user['last_name'];
$subject = $user['subject'];
$sw1 = $user['sw1'];
$sw2 = $user['sw2'];
$sw3 = $user['sw3'];
$qz1 = $user['qz1'];
$qz2= $user['qz2'];
?>
<tr>
<td><h6><?php echo $first; ?> <?php echo $last; ?></h6></td>
<!-- Written Works -->
<td><input type="text" name="sw1" value="<?php echo $ws1; ?>"></td>
<td><input type="text" name="sw2" value="<?php echo $ws2; ?>"></td>
<td><input type="text" name="sw3" value="<?php echo $ws3; ?>"></td>
<td><input type="text" name="qz1" value="<?php echo $ws4; ?>"></td>
<td><input type="text" name="qz2" value="<?php echo $ws5; ?>"></td>
</tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="submit">
</form>
Query for saving the rows:
It saves but only if the value of the columns in a row are the same.
Please help me solve this problem. Thanks In advance.
<?php
if ($_POST["submit"]) {
$sw1 = $_POST['sw1'];
$sw2 = $_POST['sw2'];
$sw3 = $_POST['sw3'];
$qz1 = $_POST['qz1'];
$qz2 = $_POST['qz2'];
$WST = $sw1 + $sw2 + $sw3 + $qz1 + $qz2;
$WSP1 = ($WST / 150 )*100;
$WSP = number_format((float)$WSP1, 2, '.', '');
$sql="UPDATE tbl_quarter1 set sw1 = '$sw1' , sw2 = '$sw2',
sw3 = '$sw3', qz1 = '$qz1', qz2 = '$qz2',
WST='$WST', WSP='$WSP'";
mysql_query($sql) or die(mysql_error());
}
?>
</body>
</html>
In the form you need to pass the firstname and lastname
<input type="hidden" name="first_name" value="<?php echo $first; ?>" />
<input type="hidden" name="last_name" value="<?php echo $last; ?>" />
And in the processing script you could update the rows with respect to the firstname and lastname
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$sql="UPDATE tbl_quarter1 set sw1 = '$sw1' , sw2 = '$sw2',
sw3 = '$sw3', qz1 = '$qz1', qz2 = '$qz2', WST='$WST',
WSP='$WSP' WHERE first_name = '$first_name' AND
last_name = '$last_name' ";
Form.html
<html>
<head><title>PHP Form</title>
</head>
<body bgcolor = "#b3ffff">
<div>
<h1 align = "center" border = "5">Dream media solution</h1>
</div><br>
<div>
<form method = "post" action = "welcome.php">
<table width = "640" align = "center" border = "5" border-color = "red">
<tr>
<th>Name:</th>
<th><input type = "text" name = "uname" placeholder = "Enter ur Name" size="28"></th>
</tr>
<tr>
<th>Email:</th>
<th><input type = "email" name = "uemail" placeholder = "Enter ur Email" size="28"></th>
</tr>
<tr>
<th>Password:</th>
<th><input type = "password" name = "upass" placeholder = "Enter ur Password" size="28"></th>
</tr>
<tr>
<th>Address:</th>
<th><textarea size="26" name="address" rows="3" cols="26"></textarea></th>
</tr>
<tr>
<th>Gender:</th>
<th><input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male</th>
</tr>
<tr>
<th>Course:</th>
<th><input type="checkbox" name="course[]" value="PHP">PHP
<input type="checkbox" name="course[]" value="Java">Java
<input type="checkbox" name="course[]" value=".NET">.NET
<input type="checkbox" name="course[]" value="Web Designing">Web Designing</th>
</tr>
<tr>
<td colspan = "2" align = "center"><input type = "submit" value = "login" name = "subname">
<input type = "reset" value = "clear"><td>
</tr>
</table>
</form>
</div>
</body>
</html>
welcome.php
<body bgcolor = "pink">
<font size = "6" color = "yellow">
<?php
if (isset($_POST['subname']))
{
$counter = 1;
$name = $_POST['uname'];
$email = $_POST['uemail'];
$pass = $_POST['upass'];
$gender = $_POST['gender'];
$cou = implode(",", $_POST['course']);
$address = $_POST['address'];
//Database connection
$con = mysqli_connect("localhost", "root", "");
// create databse
mysqli_query($con, "CREATE DATABASE sms");
//select database
mysqli_select_db($con, "sms");
//Create table
$ct = "CREATE TABLE student1(sno INTEGER(3) AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20), email VARCHAR(20), password VARCHAR(20), address VARCHAR(50), gender VARCHAR(30), course VARCHAR(30))";
//Excute table through database
mysqli_query($con,$ct);
//Insert records into table through database
$res = mysqli_query($con, "INSERT INTO student1 VALUES('', '$name', '$email', '$pass','$address', '$gender', '$cou')");
echo "<table width = '640' align = 'center' border = '5' bordercolor = 'red' bgcolor='green' cellpadding = '12'>";
$result = mysqli_query($con, "SELECT * FROM student1");
print_r ($result);
echo "<tr>";
echo "<th>Sno</th>";
echo "<th>Name</th>";
echo "<th>Email</th>";
echo "<th>Password</th>";
echo "<th>Address</th>";
echo "<th>Gender</th>";
echo "<th>Course</th>";
echo "<tr>";
echo "<th>".$counter."</th>";
echo "<th>".$_POST['uname']."</th>";
echo "<th>".$_POST['uemail']."</th>";
echo "<th>".$_POST['upass']."</th>";
echo "<th>".$_POST['address']."</th>";
echo "<th>".$_POST['gender']."</th>";
echo "<th>".$cou."</th>";
echo "</tr>";
echo "</table>";
if ($res) {
$msg = "Student Details uploaded successfully";
}
else
{
$msg = "There is Error in Details please checkout";
}
}
?>
</font>
My database name is sms and table name is student1.
Here i am getting only one record in webpage to show.
But i need over all how many records in database i will loop it and show in webpage, How is it possible please help me.
If you want to show all database records please try below code :
echo "<table width = '640' align = 'center' border = '5' bordercolor = 'red' bgcolor='green' cellpadding = '12'>";
$result = mysqli_query($con, "SELECT * FROM student1");
echo "<tr>";
echo "<th>Sno</th>";
echo "<th>Name</th>";
echo "<th>Email</th>";
echo "<th>Password</th>";
echo "<th>Address</th>";
echo "<th>Gender</th>";
echo "<th>Course</th>";
echo "</tr>";
$i = 1;
while($row = mysql_fetch_assoc($result)){
echo "<tr>";
echo "<th>".$i."</th>";
echo "<th>".$row['name']."</th>";
echo "<th>".$row['email']."</th>";
echo "<th>".$row['password']."</th>";
echo "<th>".$row['address']."</th>";
echo "<th>".$row['gender']."</th>";
echo "<th>".$row['course']."</th>";
echo "</tr>";
$i++;
}
echo "</tr>";
echo "</table>";
use while loop { }..
<?php
$sql=$con,"SELECT * FROM student1";
$i = 1;
$select = mysql_query($sql);
while($row = mysql_fetch_assoc($select)){
// Set your Values
$i++;
} ?>
OR
refer to W3Schools
make changes on your display (form html) page by adding loop or dynamic loop to display the content... use this code and change according to it..
// Create connection
thanks for taking a look at this. I have been stuck at this problem for awhile basically i am doing a recruitment agency website for my school project. I am doing the function where i can view all the candidate who applied for any job and i can choose from the dropdown box whether to "approval", "denied", or remain as "pending" which it should update the table in the database to the option i chose and it will reflect at the candidate's page. However with the codes i am using right now, it is able to display all the information i need from the different table on the page but when i try to submit the details, it only works for the last guy that applied and not the rest.
This is the form :
<form method="post" action="doEditStatus.php">
<div align ="center">
<table border='1' width ="500">
<tr>
<td> <b> ID </b></td>
<td> <b> Candidate name </b></td>
<td> <b> Job ID </b></td>
<td> <b> Job title </b></td>
<td> <b> Company </b></td>
<td> <b> Shortlist status </b></td>
</tr>
while ($row = mysqli_fetch_array($result)) {
$jobid = $row['Job_id'];
$canid = $row['Candidate_id'];
?>
<tr>
<td><?php echo $canid; ?></td>
<input type="hidden" name="can_id" value=<?php echo $canid ?>>
<input type="hidden" name="job_id" value=<?php echo $jobid ?>>
<?php
$query2 = "SELECT * FROM candidate WHERE Candidate_id =$canid";
$result2 = mysqli_query($link, $query2) or die(mysqli_error($link));
while ($row2 = mysqli_fetch_array($result2)) {
$canname = $row2['First_name']." ".$row2['Last_name'];
?>
<td><?php echo $canname; ?></td>
<?php
}
$query3 = "SELECT * FROM jobs WHERE Job_id =$jobid";
$result3 = mysqli_query($link, $query3) or die(mysqli_error($link));
while ($row3 = mysqli_fetch_array($result3)) {
$jobname = $row3['Job_title'];
$comid = $row3['Company_id'];
?>
<td><?php echo $jobid; ?></td>
<td><?php echo $jobname; ?></td>
<?php
}
$query4 = "SELECT * FROM company WHERE Company_id =$comid";
$result4 = mysqli_query($link, $query4) or die(mysqli_error($link));
while ($row4 = mysqli_fetch_array($result4)) {
$comname = $row4['Company_name'];
?>
<td><?php echo $comname; ?></td>
<?php
}
?>
<td>
<select id="id_status" name="shortlist_status">
<option value="0">Pending...</option>
<option value="1">Shortlist</option>
<option value="2">Denied</option>
</select>
</td>
</tr>
<?php
}
?>
</table>
</div>
<input type="submit" value="Submit"/>
</form>
This is the dosubmit page:
<?php
include "dbFunctions.php";
session_start();
$candidate_id = $_POST['can_id'];
$job_id = $_POST['job_id'];
$status = $_POST['shortlist_status'];
$insertQuery = "UPDATE application SET Shortlist_status = '$status' WHERE Candidate_id = $candidate_id AND Job_id = $job_id";
$inserted = mysqli_query($link, $insertQuery) or die(mysqli_error($link));
if($inserted)
{
$message = 'Profile edited successfully <br>Home';;
echo $candidate_id;
echo $status;
}
else
{
$message = "Profile edited failed";
}
echo $message;
?>
Give all your inputs names that end with []. PHP will then create an array for each of them in $_POST. E.g.
<input type="hidden" name="can_id[]" value=<?php echo $canid ?>>
<input type="hidden" name="job_id[]" value=<?php echo $jobid ?>>
Then your PHP can do:
$insertQuery = "UPDATE application SET Shortlist_status = ? WHERE Candidate_id = ? AND Job_id = ?";
$insertStmt = mysqli_prepare($link, $insertQuery);
mysqli_stmt_bind_param($insertStmt, "iii", $status, $candidate_id, $job_id);
foreach ($_POST['can_id'] as $i => $candidate_id) {
$job_id = $_POST['job_id'][$i];
$status = $_POST['shortlist_status'][$i];
$inserted = mysqli_execute($insertStmt) or die(mysqli_error($insertStmt));
if ($inserted) {
...
} else {
...
}
}