I've a job list page, displaying all jobs and there are checkbox next to each one, and there is an Add button at the bottom of the page, to add it to JobCart.php
I honestly don't know how to pass multiple record ID or single ID to jobCart.php
I want the when the user to click the button "Add" pass all selected ID to jobCart.php
please help me
<?php
// adding JobsLists.php to this page to interact witht it.
require ("../JobsLists.php");
//Connect to DB
//include_once("Project/CIEconn.php");
$mysqlCON= mysqli_connect("localhost", "root", "","CIE") or die(mysqli_connect_error());
mysqli_select_db($mysqlCON,'CIE') or die ("no database");
$ID = isset($_POST['Id']); // 1 2
if( isset($_POST['pick']) ){
if( empty($ID) || $ID == 0 ){
echo"<h4> please choose something to move to your job list </h4>";
}else{
// Code here ..
// here here ONLY for TEST to check if I can interact eith jobLists.php
addJob();
// to get all ID from each selected job
$impid = implode("' , '" , $_POST['Id']);
}
}
$sqlCommand = "SELECT * FROM Fiscal WHERE NoStudent > '0' ";
$result = mysqli_query($mysqlCON,$sqlCommand) or die(mysqli_error($mysqlCON));
echo '
<form action= "Fiscal.php" method = "post">
<table width ="100%" cellpadding ="4" border="1" >
<tr>
<th>Check </th>
<th>Jobs Name</th>
<th>Description</th>
<th> No Students needed</th>
<th>Due Date</th>
</tr>';
while ($row = mysqli_fetch_array($result) ){
// name = 'Id[]'
echo "<tr>
<td> <input type='checkbox' name='Id[]' value='". $row['Id'] ."' /> </td>
<td> ". $row['JobName'] ." </td>
<td> ". $row['Description'] ." </td>
<td> ". $row['NoStudent'] . "</td>
<td>". $row['DueDate'] ." </td>
</tr>";
}
echo '
</table>
<br/>
<div align="center">
<input type="submit" name="pick" value="Add Job" />
<input type="reset" value="Clear Marks" />
</div>
</form>
';
?>
<html>
<head><title> Fiscal </title></head>
<br>
<body>
</body>
</html>
First of all, start session at the very top of your page, like this:
<?php
session_start();
?>
And during the form processing store $_POST['Id'] array to $_SESSION superglobal and redirect the user to jobCart.php page using header() function.
And one more thing, $_POST['Id'] would be an array, so use count() function to see it's empty or not. So your code should be this:
// your code
if(isset($_POST['pick'])){
if(count($_POST['Id'])){
// store `$_POST['Id']` array to `$_SESSION` superglobal
$_SESSION['ids'] = $_POST['Id'];
// redirect the user to jobCart.php page
header("Location: jobCart.php");
exit();
}
}
// your code
And in jobCart.php you can do something like this:
$impid = implode("','" , $_SESSION['ids']);
// rest of your code
Related
I have a MYSQL table with Update link button on each row. he Update link goes to update.php which has a form. now the problem is i want to fetch the id from the row clicked on to update.php and show that id on update form in id field. i have transfered the id variable through link. but in other .php file it is printing anything.
i want to print id in update form field when i click on update button
Here is the code in index.php file
Display.php=>
<html>
<head><title>Support Page</title></head>
<body>
<table border="2">
<tr>
<th>ID</th>
<th>NAME</th>
<th>Email</th>
<th>phone no</th>
<th>Product Name</th>
<th>Company</th>
<th>Query</th>
<th>Any Other Info</th>
<th>Status</th>
<th>Date</th>
<th>Operations</th>
</tr>
<?php
$query ="SELECT * FROM query_data";
$data = mysqli_query($conn,$query);
$total = mysqli_num_rows($data);
echo $result['id']." ".$result['Name']." ".$result['Email']." ".$result['phone_no']." ".$result['Product_Name']." ".$result['Company']." ".$result['Query']." ".$result['Any_Other_Query']." ".$result['Status']." ".$result['Date'];
if($total!=0)
{
while($result = mysqli_fetch_assoc($data))
{
echo "
<tr>
<td>".$result['id']."</td>
<td>".$result['Name']."</td>
<td>".$result['Email']."</td>
<td>".$result['phone_no']."</td>
<td>".$result['Product_Name']."</td>
<td>".$result['Company']."</td>
<td>".$result['Query']."</td>
<td>".$result['Any_Other_Info']."</td>
<td>".$result['Status']."</td>
<td>".$result['Date']."</td>
<td><a href = 'http://mexyz.tech/?page_id=586?i=$result[id]'>Update</td>
</tr>";
}
}else{
echo "No record found";
}
?>
</table>
</body>
</html>
and this is update.php=>
<?php
include("connection.php");
$id = $_GET['i'];
?>
form action="" method="GET">
Enter id : <input type="text" value="<?php echo "id" ?>" name="id" required>
<br><br>
Enter Query Code: <input type="text" name="QC">
<br><br>
<td>
<select name="Status">
<option>Choose Option</option>
<option>Pending</option>
<option>Assigned</option>
<option>Resolved</option>
</select>
</td>
<br><br>
<input type="submit" value="Submit" name="Submit">
</form>
<?php
if (isset($_POST['Submit'])) {
$ids = $_POST['id'];
$s = $_POST['Status'];
$QC = $_POST['QC'];
$tablename = "query_data";
$data = array("Status" =>$s, "Query_Code" =>$QC);
$wherecondition = array('id' => $ids);
$updated = $wpdb->update( $tablename, $data, $wherecondition );
// $sql = $wpdb->insert("query_data",array("Status" =>$s,"Query_Code" =>$QC));
if ($updated == true) {
echo "<script> alert('Submitted Successfully!...')</script>";
}
}
?>
</div><!-- #primary -->
<?php
if (astra_page_layout() == 'right-sidebar') :
get_sidebar();
endif;
get_footer();
I dont know exactly what you are trying to achieve from your code but
you should pass your update link with a query string if you want to get the id in your update.
this is how to pass the link with a query string
<td>Update</td>
if you do it that way then got to your update page
and do this
if (isset($_GET[id])){
$id = $_GET[id];
}
hello guys i have this problem that i couldn't solve the thing is i have two buttons one for delete and the other for edit, the delete is working flawlessly, but edit button doesn't seems to work to make it redirect to a php file + how i can get the meeting name with edit button when it's redirect to another page don't know how here's my code
<table class="table table-striped custab" >
<thead>
<tr>
<th>Title</th>
<th>Chairman</th>
<th>Summary</th>
<th> Date & Time</th>
</tr>
<?php
$findMeetings = "SELECT * FROM `meeting` WHERE chairman='".$name."'";
$result = mysqli_query($db, $findMeetings);
$numRows = mysqli_num_rows($result);
if($numRows == 0){
$empty = "<div class='alert alert-danger'>You are currently managing no meetings!</div>";
}
else{
$x = 0;
while($rows = mysqli_fetch_array($result)){
$title = $rows['title'];
$chairman = $rows['chairman'];
$date = $rows['time'];
$summary = $rows['summary'];
$meeting = "
<tr>
<th>".$title."</th>
<th>".$chairman."</th>
<th>".$summary."</th>
<th>".$date."</th>
<th><form method='post'>
<input type='submit' class='btn btn-success' name='edit".$x."' value='Edit'/>
<input type='submit' class='btn btn-danger' name='delete".$x."' value='Delete'/>
</form></th>
</tr>
";
echo $meeting;
if(isset($_POST['delete'.$x.''])){
$query = "DELETE FROM meeting WHERE title='".$title."' LIMIT 1";
if($result = mysqli_query($db, $query)){
header("Location:managemeeting.php");
}
}
}
}
?>
</thead>
<tbody>
</tbody>
</table>
so how to get the meeting name and the passed it to editmeeting.php cause there's multiple data.
if i do it like delete button nothing happen like this
if(isset($_POST['edit'.$x.''])){
header("Location:editMeeting.php");
}
You should wrap a <form> around each submit button, and specify the action in each <form> so that it posts to the correct url with respect to the button the <form> is wrapped around.
Then use <hidden> fields inside each <form> to pass data to the url you are posting to. Example: <input type="hidden" name="row_id" value="99" />
Look like everything is working fine with this code but in fact fails to update the database, Data are displayed correctly while fetching data but when i press update Button the data disappear but no update has been executed. It look fine to me but seems i am wrong.
This is a project for my professor so i don't care for the SQL injection and others.
<html>
<head>
<link rel="stylesheet" type="text/css" href="btnstyle.css">
<title>Managament System</title>
</head>
<body>
<h1>TU Chemnitz Student managament system</h1>
<br>
ADD Person
Edit Person
Manage Boards
Manage Departments
Search N&S
Triple Search
Membership
<br>
<br>
<?php
// set database server access variables:
$host = "localhost";
$user = "";
$pass = "";
$db = "";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$querys = "SELECT * FROM tblperson";
// execute query
$result = mysql_query($querys) or die ("Error in query: $query. ".mysql_error());
echo "<table border=1 align=center>
<tr>
<th>Personal ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Deparment</th>
<th>Board</th>
<th>Marticulation Number</th>
<th>Reg Date</th>
<th>Action</th>
</tr>";
while($row = mysql_fetch_array($result)) {
?>
<?php
echo '<tr>';
echo '<td>'. $row['personid'].'</td>';
echo '<td>'. $row['personname'].'</td>';
echo '<td>'. $row['personsurname'].'</td>';
echo '<td>'. $row['persondepartment'].'</td>';
echo '<td>'. $row['personboard'].'</td>';
echo '<td>'. $row['martinumber'].'</td>';
echo '<td>'. $row['personregdate'].'</td>';
echo '<td>'.' EDIT '.'</td>';
}
?>
</body>
</html>
and this is the edit file which seems to problematic.
<?php
include_once('coneksioni.php');
if(isset($_GET['edit']))
{
$personid = $_GET['edit'];
$res = mysql_query("SELECT * FROM tblperson WHERE personid='$personid'");
$row = mysql_fetch_array($res);
}
if(isset($_POST['newpersonname']))
{
$newpersonname = $_POST['newpersonname'];
$personid = $_POST['personid'];
$sql = "UPDATE tblperson SET personname = '$newpersonname' WHERE personid = '$personid'";
$res = mysql_query($sql) or die ("Cant be updated");
echo "< meta http-equiv='refresh' content='0;url=home.php'>";
}
?>
<form action="edit20.php" method="POST">
<table border="0">
<tr>
<td>First Name</td>
<td><input type="text" name="newpersonname" value="<?php echo $row[1];?>" maxlength="30" size="13"></td>
</tr>
<tr>
<td>Last Name</td>
<td> <input type="text" name="personsurname" value="<?php echo $row[2];?>" maxlength="30" size="30"></td>
</tr>
<tr>
<td>Department</td>
<td>
<select name='persondepartment'>
<option>Production</option>
<option>Sales</option>
</select>
</td>
</tr>
<tr>
<td>Board</td>
<td>
<select name='personboard'>
<option>Evaluation</option>
<option>Executive</option>
<option>Research</option>
</select>
</td>
</tr>
<tr>
<td>Marticulation Number</td>
<td> <input type="text" name="martinumber" maxlength="60" size="30"></td>
</tr>
<tr>
<td>Date of Registration</td>
<td><input type="date" name="personregdate" maxlength="7" size="7"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value=" Update"></td>
</tr>
</table>
</form>
You are looking for personid when the Update button is pressed on the form in edit20.php but that value has never been set so it will be empty and the update will fail.
After
<form action="edit20.php" method="POST">
add:
<input type="hidden" name="personid" value="<?php echo $personid; ?>">
On edit page seem your confusing the same variable with different values. If you state $personid variable to contain the edit value from get, then just re-use the variable don't assign new value. On this line you assign new value :
$personid = $_POST['personid'];
Don't assign new value since it has the initial value already to use just set the variable global for usage
$personid = $_GET['edit'];
Or else create a hidden element and pass edit value into it.
Please add name attribute for your update button
<td colspan="2"><input type="submit" name="update" value=" Update"></td>
and chk whether the update button set or reset as in the place of
if(isset($_POST['newpersonname'])) // change text 'newpersonname' as 'update'
You use a variable that doesn't excist:
<?php
include_once('coneksioni.php');
if(isset($_GET['edit']))
{
$personid = $_GET['edit'];
$res = mysql_query("SELECT * FROM tblperson WHERE personid='$personid'");
$row = mysql_fetch_array($res);
}
if(isset($_POST['newpersonname']))
{
$newpersonname = $_POST['newpersonname'];
$personid = $_POST['personid']; // this doesn't excist
$sql = "UPDATE tblperson SET personname = '$newpersonname' WHERE personid = '$personid'";
$res = mysql_query($sql) or die ("Cant be updated");
echo "< meta http-equiv='refresh' content='0;url=home.php'>";
}
?>
$personid = $_POST['personid']; doesn't excist in your code. Its simply a piece of code you put in there to probably proces, but forgot to define the variable in the code. Place the following in your form.
<input type="hidden" name="personid" value="<?php echo $_GET['edit']; ?>">
You only use this just once because you send the form back after proces to your home, hence it wont be used anymore. You can also use the avariable you defined as $personid; on that position.
If that fails, something maybe wrong in your query. Try to echo out the query (remove qucikly the meta command) by simply just do echo $sql after you do the sql query. 9 out of 10 times, it's a typo.
Here Is my problem: I do not get any error with my code but my problem is when i click the 'Delete Multiple' Button it does nothing not even reload the page.
Note: By The Way the redirect_to(); function i created so do not get confused by thinking that is a php function or anything
PHP Code:
display_errors(E_ALL);
if(isset($_POST['muldelete'])) {
$mul = $_POST['checkdelete'];
$sql = "DELETE FROM cmarkers WHERE id = " . $mul;
$result = mysqli_query($db, $sql);
redirect_to("elerts.php");
}
HTML Code:
<form action="elerts.php" method="post">
<table class="table table-striped">
<tr>
<td> </td>
<td>Date</td>
<td>Comment</td>
<td>Actions</td>
</tr>
<?php
$sql = "SELECT * FROM cmarkers";
$result = $db->query($sql);
while ($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><input type="checkbox" name="checkdelete[]" value="<?php echo $row['id']; ?>" /></td>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['comment']; ?></td>
<td>DeleteEdit</td>
</tr>
<?php
}
?>
<input type="submit" name="muldelete" value="Delete Multiple" />
</table>
</form>
Thank You
If you need more info please let me know
First, your code contain some attention and placements errors.
input between <table> outer of td's is incorrect.
You can't make a multiple delete if you generate one form by value to
delete.
Fix them.
Getting Array of muldelete
To all the checked inputs, you must add the array field symbol
to clusterize the name "muldelete" to a post array.
<td><input type="checkbox" name="checkdelete[]" value="<?php $row['id']; ?>" /></td>
PHP side
Now you can fetch whole deletion array, like this:
if(!empty($_POST["muldelete"]))
{
$mul = join(',', $_POST['checkdelete']);
// Using IN() to make only one query for all records instead of multiple
// ex: IN(3, 4, 54, 8)
$query = "DELETE FROM cmarkers WHERE id IN(".$mul.")";
$result = mysqli_query($db, $query);
redirect_to("elerts.php");
}
Security
If ID's are integer value, you can prevent string injection into the sql query
$mul = array_map(function($id)
{
return intval($id);
}, $mul);
Your button is outside the <form></form> tags, so it is not related to the form elements or the form method at all. Instead of having a different form for each checkbox you should surround the entire table with the form tags thus ensuring that all the checkboxes and the button are in the same form.
<form method='post' action='elerts.php'>
<table class="table table-striped">
...all your table data including checkboxes...
<input type="submit" name="muldelete" value="Delete Multiple" />
</table>
</form>
I think because You are closing form tag earlier than submit button.
Try to put whole table into and should work.
PHP should looks like
display_errors(E_ALL);
if(isset($_POST['muldelete'])) {
$mul = implode(',',$_POST['checkdelete']);
$sql = "DELETE FROM cmarkers WHERE id IN(" . $mul.")";
$result = mysqli_query($db, $sql);
redirect_to("elerts.php");
}
My main issue that I am running into is basically this:
I have a while loop that generates results from a query. With the results that have been generated, I want the ability to update the table the original query was from.
The query produces the expected results, but the table is not being updated when I click the REMOVE button. I am also trying to find a solution for the results to be updated after the UPDATE query executes...
<?php
$sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo
"
<tr>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['year'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['make'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['model'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'><input type='submit' name='remove' value='REMOVE' style='background-color:#C33;color:white;padding:10px;border-radius:5px;width:70px'/></td>
</tr>";
if(isset($_POST['remove'])){
$removeSql = "UPDATE `table`.`vehicles` SET `display`='0' WHERE `vin`='{$row['vin']}'";
mysql_query($removeSql) or die('check that code dummy');
}
}
mysql_close($connection);
?>
That's a submit button, will not work without form tag. You can't do it this way.
You can write the remove code on a separate page and convert that submit button to normal button and pass vin id on click of that button and call that page using ajax.
Or if you don't know ajax and want to do it on that page itself then do it this way :
<?php
$sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo
"
<tr>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['year'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['make'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['model'],"</td>
<td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>
<form action="" method="POST">
<input type="hidden" name="vin_id" value="<?php echo $row['vin']; ?>">
<input type='submit' name='remove' value='REMOVE' style='background-color:#C33;color:white;padding:10px;border-radius:5px;width:70px'/>
</form></td>
</tr>";
}
if(isset($_POST['remove'])){
$removeSql = "UPDATE `table`.`vehicles` SET `display`='0' WHERE `vin`='".$_POST['vin_id']."'";
mysql_query($removeSql) or die('check that code dummy');
}
mysql_close($connection);
?>