I've this code in php, and it retrieve all the value I've in my database, and I want the user not be able to choose or tamper with the one that has expired date,
please can you help me ?
my code below only show u the word 'Expired' and 'Not Expired' on the web, since I'm only Echoing it.
I want to just disable the check box, and not let the user be able to change anything like the statues or remove the job.
please can you help me ?
$result = mysqli_query($dbCIE,$sqlCommand) or die(mysql_error());
echo "<form action='JobsLists.php' method='post'>";
while($row = mysqli_fetch_array($result))
{
$exp_date = $row['DueDate'];
$today_date = date('Y/m/d');
$exp=strtotime($exp_date);
$td=strtotime($today_date );
if($td>$exp){
echo"Expiered";
}else{
echo"NOT Expiered";
}
echo "<tr>";
echo "<td> <input type='checkbox' id='myCheck' name='JobId[]' value='". $row['JobId'] ."' /> </td>";
echo "<td align=center>" . $row['SSU'] . "</td>";
echo "<td align=center>" . $row['JobName'] . "</td>";
echo "<td align=center> " . $row['Description'] . "</td>";
echo "<td align=center>" . $row['DueDate'] . "</td>";
echo "<td>"."<select name='JobStatus[".$row['JobId']."]'>";
if($row['JobStatus'] == "InProgress"){
echo "<option value='InProgress' selected>In Progress</option>";
echo "<option value='Completed'>Completed</option>";
} else {
echo "<option value='InProgress'>In Progress</option>";
echo "<option value='Completed' selected> Completed </option>";
}
echo "</select>" . "</td>"; // need to be worked on..
echo "</tr>";
}
"</table>";
?>
Why not just not print it out?
if (!$td->exp)
echo "<td> <input type='checkbox' id='myCheck' name='JobId[]' value='". $row['JobId'] ."' /> </td>";
It's better to just not show a button or input than to disable it sometimes. Inputs can be disabled with the DISABLED keyword
<input type="checkbox" name="foo" DISABLED>
Related
Can anyone suggest some alternative solution for this problem.
I've made a popup form which i use css and javascript to trigger the display to none or flex every time i click into a specific button which is great. But this method seems to not work on a table as you can see below i've done a simple query which i just fetch some of the essentials and included some buttons to use to trigger the popup form.
PHP/HTML CODE
<tbody>
<?php
$res=mysqli_query($link,"SELECT CONCAT(c.firstname, ' ', c.lastname) AS fullname, c.* FROM user_registration c");
while($row=mysqli_fetch_array($res))
{
echo "<tr>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; ?> <img src="<?php echo $row["image"]; ?>" height="100" width="100"> <?php echo "</td>";
echo "<td>"; echo $row["fullname"]; echo "</td>";
echo "<td>"; echo $row["username"]; echo "</td>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; ?> <button class="btn btn-success" style="width: 100%">Accept</button><?php echo "</td>";
echo "<td>"; ?> <button class="btn btn-danger" style="width: 100%">Decline</button><?php echo "</td>";
echo "<td>"; ?> <button class="btn btn-success" style="width: 100%">View Message</button><?php echo "</td>";
echo "</tr>";
}
?>
</tbody>
JAVASCRIPT CODE
document.getElementById("declineB").addEventListener("click", function(){
document.querySelector(".popup3").style.display = "flex";
})
document.getElementById("closeDecB").addEventListener("click", function(){
document.querySelector(".popup3").style.display = "none";
})
When you have multiple elements with id declineB, document.getElementById("declineB") can actually only get the first element with id declineB. The effect you want will only appear when an element whose id is declineB. When click others, no click event will be triggered.
When you use css class, you can add click event to every html element of same class:
let elements = Array.from(document.getElementsByClassName('spacer'))
for (let element of elements) {
element.addEventListener('click', ...)
}
I am trying to create a page to allow toggling on and off certain forums in website, created from raw data in an SQL server. However I need each to have an individual ID so I can show/hide them based on user preference. I am not sure how to go about it. Here is my existing code, disregard the connection values, I am hiding them on purpose. thanks.
$db_host = "host";
$db_username = "username";
$db_pass = "pass";
$db_name = "name";
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$query = $db->query('SELECT p.name, p.company, o.prodtype AS Type
FROM ownedproducts AS o
JOIN product as p ON p.productID = o.productID
WHERE o.usersID = 2');
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title> User Forum Selection </title>
</head>
<body>
<div>
<input type="text" id="userid">
</div>
<div>
<hr>
<table id=table border = '2'>
<tr id=table-row>
<th id=table-header>Name</th>
<th id=table-header>Company</th>
<th id=table-header>Type</th>
</tr>
<?php
while ($row = $query->fetch())
{
echo "<tr id=table-row >";
echo "<td>" . $row['name'] ."</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
</html>
What about using the product id ? That sounds logical here.
Select it :
$query = $db->query('SELECT p.productID, p.name, p.company, o.prodtype AS Type ...
Then use it in your rows :
while ($row = $query->fetch())
{
echo "<tr id='table-row-" . $row['id'] . "' >";
echo "<td>" . $row['name'] ."</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}
Always use single and double quote in id as (id=' ', id=" ")
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title> User Forum Selection </title>
</head>
<body>
<div>
<input type="text" id="userid">
</div>
<div>
<hr>
<table id=table border = '2'>
<tr id=table-row>
<th id=table-header>Name</th>
<th id=table-header>Company</th>
<th id=table-header>Type</th>
</tr>
<?php
while ($row = $query->fetch())
{
echo "<tr id=table-row >";
echo "<td>" . $row['name'] ."</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
</html>
use it in your rows :
<?php
foreach( $query->fetch() as $rows=> $row)
{
echo "<tr id='table-row-'.$rows >";
echo "<td>" . $row[or</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}
?>
I'd probably do it in a foreach and use the key.
foreach( $query->fetch() as $key => $row)
{
echo "<tr id='table-row-'.$key >";
echo "<td>" . $row['name'] ."</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}
I am not able to update one column field. Please Suggest me what is the wrong thing in my code
index.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "logistics";
$lastId="";
//create connection
$con = mysqli_connect($host, $user, $pass, $db_name);
$result = mysqli_query($con,"SELECT * FROM notification");
?>
<div class="table-inner-wrapper">
<h5 class="text- blll"> Active Alerts </h5>
<table class="table table-hover table-striped">
<tr class="t_head">
<th>ID </th>
<th>Forklift ID</th>
<th>Timestamp</th>
<th>Duration</th>
<th>Alert Details</th>
<th></th>
<th>Remark</th>
<th></th>
</tr>
<?php
while($row = mysqli_fetch_array($result)){
echo "<form action='' id='remarks' method='post'>";
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['forklift_id'] . "</td>";
echo "<td>" . $row['noti_start'] . "</td>";
echo "<td>" . $row['duration'] . " hr</td>";
echo "<td>" . $row['alert_details'] . "</td>";
echo "<td><i class='email' id='". $row['id'] ."'> <i class='fa fa-inbox fa-2x'> </i> </i> </td>";
echo "<td><textarea class='remarks' id='".$row['id']."'> ".$row['remarks']." </textarea></td>";
echo "<td><input type='button' class='btn btn-info remark' value='submit' id='".$row['id']."'></td>";
echo "</tr>";
echo "</form>";
}
?>
</table>
</div>
<script type="text/javascript">
$(() => {
$(document).ready(function(){
$(".remark").on('click',function(e){
e.preventDefault();
var id = $(this).attr('id');
var remarks = $("textarea.remarks").val();
// alert(remarks);
// alert(id);
$.ajax({
url:'remark.php',
method:'POST',
data: {id: id, remarks: remarks},
success:function(data){
alert(data);
// return data;
}
});
});
});
})
</script>
remark.php
<?php
$conn = new mysqli('localhost', 'root', '', 'logistics');
$remarks = $_POST['remarks'];
echo $remarks;
$id = $_REQUEST['id'];
echo $id;
$sql = "UPDATE notification SET remarks='".$remarks."' WHERE id='".$id."' " ;
if($conn->query($sql)===TRUE){
echo "DATA updated";
}
?>
I am trying to update remarks column value on submit based on row id but it's updating only a first row of column value and if i click on the remaining rows it is not updating the remarks value.
A couple things:
I would change $id = $_REQUEST['id']; to $id = $_POST['id'];
Secondly, your <form> tag is inside your while loop which means you are echoing out a new form on every iteration. All of the forms will have the same id. This will cause you problems and fits the type of behavior that you are describing. Remove the <form> tags from the inside of the loop like so:
echo "<form action='' id='remarks' method='post'>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['forklift_id'] . "</td>";
echo "<td>" . $row['noti_start'] . "</td>";
echo "<td>" . $row['duration'] . " hr</td>";
echo "<td>" . $row['alert_details'] . "</td>";
echo "<td><i class='email' id='". $row['id'] ."'> <i class='fa fa-inbox fa-2x'> </i> </i> </td>";
echo "<td><textarea class='remarks' id='".$row['id']."'> ".$row['remarks']." </textarea></td>";
echo "<td><input type='button' class='btn btn-info remark' value='submit' id='".$row['id']."'></td>";
echo "</tr>";
}
echo "</form>";
This line:
var remarks = $("textarea.remarks").val();
will only give you the value of the first textarea with the class remarks. You need to access the remarks from the textarea associated with the button instead. You do have a problem though that you have multiple elements with the same id, so you need to fix that first. Try changing this code:
echo "<td><i class='email' id='". $row['id'] ."'> <i class='fa fa-inbox fa-2x'> </i> </i> </td>";
echo "<td><textarea class='remarks' id='".$row['id']."'> ".$row['remarks']." </textarea></td>";
to
echo "<td><i class='email' id='e". $row['id'] ."'> <i class='fa fa-inbox fa-2x'> </i> </i> </td>";
echo "<td><textarea class='remarks' id='t".$row['id']."'> ".$row['remarks']." </textarea></td>";
Now your textarea field has a unique id which is still related to $row['id']. So in your event code, you can write:
var remarks = $("#t" + id).val();
to get the value of remarks associated with that button.
This is the code, im trying to get the value of each TD with id=tel2 and checkbox is checked and store all values in textarea separated with Comma ','
Any suggestion ?
echo "<div>";
if ($result->num_rows > 0) {
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th></th> <th>Nom</th> <th>Prenom</th> <th>Tel</th> <th>Classe</th> <th>Annee</th> </tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td> <input type=\"checkbox\" id=\"case\"></td>";
echo "<td>" . $row['nom'] . "</td>";
echo "<td>" . $row['prenom'] . "</td>";
echo "<td id=\"tel2\">" . $row['tel'] . "</td>";
echo "<td>" . $row['classe'] . "</td>";
echo "<td>" . $row['annee'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
echo "</div>";
?>
I'm writing a plugin and have need of the media uploader in two different functions; add program, and edit program. Both these functions present a form for the site admin to fill in. One form for adding a new program, and the other for editing an existing one (facilitated by an id variable passed in the URL).
The code I got from this page: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/ is working perfectly in the add program admin page. However, the same code is not working on the edit program page. I've checked the source of both pages, and the appropriate scripts and styles are enqueued, the javascript is present in the body, just before the form code, and the upload field and button codes are correct. Everything tis as it should be on both pages, but it only works on one of them.
Being quite a novice at javascript and jQuery, it's quite possible I'm missing something simple. Any assistance would be appreciated.
Hi cale b, the only error shown is "tb_show is not defined" which, of course, isn't good. It LOOKS like it's defined in the code, though.
Here is the code for enqueuing the scripts and styles:
function bhcprograms_manager_admin_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
}
function bhcprograms_manager_admin_styles() {
wp_enqueue_style('thickbox');
}
add_action('admin_print_scripts', 'bhcprograms_manager_admin_scripts');
add_action('admin_print_styles', 'bhcprograms_manager_admin_styles');
The javascript and form code for the one that works:
echo "<script language=\"JavaScript\">\n";
echo "jQuery(document).ready(function() {\n";
echo "jQuery('#bhc_image_button').click(function() {\n";
echo "formfield = jQuery('#bhc_image').attr('name');\n";
echo "tb_show('', 'media-upload.php?type=image&TB_iframe=true');\n";
echo "return false;\n";
echo "});\n";
echo "window.send_to_editor = function(html) {\n";
echo "imgurl = jQuery('img',html).attr('src');\n";
echo "jQuery('#bhc_image').val(imgurl);\n";
echo "tb_remove();\n";
echo "}\n";
echo "});\n";
echo "</script>\n";
echo "<form method=\"post\" action=\"\" name=\"new_program\">\n";
echo "<h4>* indicates required field</h4>\n";
echo "<h4>Program Title *</h4>\n";
echo "<input type=\"text\" size=\"40\" name=\"bhc_title\" value=\"" . str_replace('"', '"', $bhc_title) . "\" maxlength=\"255\" />\n";
echo "<h4>Program Subtitle</h4><strong>If no subtitle, leave it blank</strong><br />\n";
echo "<input type=\"text\" size=\"40\" name=\"bhc_subtitle\" value=\"" . str_replace('"', '"', $bhc_subtitle) . "\" maxlength=\"255\" />\n";
echo "<h4>Description *</h4>\n";
echo "<textarea name=\"bhc_description\" rows=\"4\" cols=\"50\" type=\"textarea\">" . $bhc_description . "</textarea>\n";
echo "<h4>Image Upload</h4><strong>Upload an image to go with this program description. If no image wanted, leave it blank</strong><br />\n";
echo "<input id=\"bhc_image\" type=\"text\" size=\"40\" name=\"bhc_image\" value=\"" . $bhc_image . "\" />\n";
echo "<input id=\"bhc_image_button\" type=\"button\" value=\"Upload Image\" />\n";
echo "<h4>What to Bring</h4><strong>If N/A, leave it blank</strong><br />\n";
echo "<textarea name=\"bhc_bring\" rows=\"4\" cols=\"50\" type=\"textarea\">" . $bhc_bring . "</textarea>\n";
echo "<h4>What is Provided</h4><strong>If N/A, leave it blank</strong><br />\n";
echo "<textarea name=\"bhc_provided\" rows=\"4\" cols=\"50\" type=\"textarea\">" . $bhc_provided . "</textarea>\n";
echo "<br /><br />\n";
echo "<h4>Start program as active?</h4>\n";
echo "<input type=\"radio\" name=\"bhc_active\" value=\"1\"" . ($bhc_active==1?' checked':'') . "> Yes<br /><input type=\"radio\" name=\"bhc_active\" value=\"0\"" . ($bhc_active==1?'':' checked') . "> No<br />\n";
echo "<br /><br />\n";
echo "<input type=\"submit\" name=\"submit\" class=\"button-primary\" value=\"Add Program\" />\n";
echo "</form>\n";
and the javascript and form codes for the one that doesn't work:
echo "<script language=\"JavaScript\">\n";
echo "jQuery(document).ready(function() {\n";
echo "jQuery('#bhc_image_button').click(function() {\n";
echo "formfield = jQuery('#bhc_image').attr('name');\n";
echo "tb_show('', 'media-upload.php?type=image&TB_iframe=true');\n";
echo "return false;\n";
echo "});\n";
echo "window.send_to_editor = function(html) {\n";
echo "imgurl = jQuery('img',html).attr('src');\n";
echo "jQuery('#bhc_image').val(imgurl);\n";
echo "tb_remove();\n";
echo "}\n";
echo "});\n";
echo "</script>\n";
/* Show the form with the details */
echo "<form method=\"post\" action=\"\" name=\"edit_program\">\n";
echo "<strong>* indicates required field</strong>\n";
/* Find out if there are events scheduled for this program ... */
$bhc_program_event = $mydb->get_results("SELECT bhc_event_id FROM $table_events WHERE bhc_program_id = $bhc_id");
/* Loop through and display programs*/
echo "<h4>Program Title *</h4>\n";
if ($bhc_program_event) {
echo "<strong>" . $bhc_title . "</strong>\n";
echo "<input type=\"hidden\" name=\"bhc_title\" value=\"" . str_replace('"', '"', $bhc_title) . "\" />\n";
} else {
echo "<input type=\"text\" size=\"40\" name=\"bhc_title\" value=\"" . str_replace('"', '"', $bhc_title) . "\" maxlength=\"255\" />\n";
}
echo "<h4>Program Subtitle</h4>\n";
if ($bhc_program_event) {
echo "<strong>" . $bhc_subtitle . "</strong>\n";
echo "<input type=\"hidden\" name=\"bhc_subtitle\" value=\"" . str_replace('"', '"', $bhc_subtitle) . "\" />\n";
} else {
echo "<strong>If no subtitle, leave it blank</strong><br />\n";
echo "<input type=\"text\" size=\"40\" name=\"bhc_subtitle\" value=\"" . str_replace('"', '"', $bhc_subtitle) . "\" maxlength=\"255\" />\n";
}
echo "<h4>Description *</h4>\n";
echo "<textarea name=\"bhc_description\" rows=\"4\" cols=\"50\" type=\"textarea\">" . $bhc_description . "</textarea>\n";
echo "<h4>Image Upload</h4><strong>Upload an image to go with this program description. If no image wanted, leave it blank</strong><br />\n";
echo "<input id=\"bhc_image\" type=\"text\" size=\"40\" name=\"bhc_image\" value=\"" . $bhc_image . "\" />\n";
echo "<input id=\"bhc_image_button\" type=\"button\" value=\"Upload Image\" />\n";
echo "<h4>What to Bring</h4><strong>If N/A, leave it blank</strong><br />\n";
echo "<textarea name=\"bhc_bring\" rows=\"4\" cols=\"50\" type=\"textarea\">" . $bhc_bring . "</textarea>\n";
echo "<h4>What is Provided</h4><strong>If N/A, leave it blank</strong><br />\n";
echo "<textarea name=\"bhc_provided\" rows=\"4\" cols=\"50\" type=\"textarea\">" . $bhc_provided . "</textarea>\n";
/* Exclude active option if registrations exist */
$nowtime = date("U");
$bhc_reg_check = $mydb->get_row("SELECT bhc_event_id FROM $table_events WHERE bhc_program_id = $bhc_id AND bhc_current_peeps > 0 LIMIT 1");
if ($bhc_reg_check) {
echo "<input type=\"hidden\" name=\"bhc_active\" value=\"1\">\n";
} else {
echo "<h4>Set program as active?</h4>\n";
echo "<input type=\"radio\" name=\"bhc_active\" value=\"1\"" . ($bhc_active==1?' checked':'') . "> Yes<br /><input type=\"radio\" name=\"bhc_active\" value=\"0\"" . ($bhc_active==1?'':' checked') . "> No<br />\n";
}
echo "<br /><br />\n";
echo "<input type=\"hidden\" name=\"bhc_id\" value=\"" . $bhc_id . "\" />\n";
echo "<input type=\"submit\" name=\"submit\" class=\"button-primary\" value=\"Edit Program\" />\n";
echo "</form>\n";
exit;