Need assistance with disabling checkboxes - php

I currently have a form as you will see below. For simplicity sake the form is condensed to the checkboxes that I'm working with. What I want to have happen is for a user to optionally click one or the other. Depending on which one is clicked, the other one should be disabled. I noticed that user "dinah" posted a similar question before and that this js fiddle was provided http://jsfiddle.net/A5TGf/19/ . However, for some reason when I applied my form id and switched the blacklist names around it wasn't working with my code. Any suggestions? Thanks
HTML/PHP
<form name="insertTicket" id="insertTicket" action="index.php" method="POST" >
<div id="ticket_hidden" style="text-align: center; clear:both;">
<div id="visible_div" style="float: left;">
<input type="checkbox" name="escalated" id ="escalated" value="Yes" onclick="doInput(this);" tabindex="18">Escalate
</div>
<div id="hidden_div" style="float: left; display:none;">
<?php
$dept = $_SESSION['dept_id'];
$get_email = mysql_query("Select email_name, dept_id, copy_user from emails where escalated = 'yes'");
while(($email = mysql_fetch_assoc($get_email)))
{
$department = explode(",", $email['dept_id']);
if(in_array($dept, $department, TRUE))
{
echo '
<input type="checkbox" name="escalated_to[]" id="escalated_to[]" value="'.$email['email_name'].'" />'.$email['email_name'].'
';
if($email['copy_user'] == 'YES')
{
echo '
<input type="text" name="emails[]" style="width: 175px; height: 20px;" placeholder="To:">
';
}
}
}
?>
</div>
<div id="visible_divX" style="float: left;">
<input type="checkbox" name="email" id="email" value="Yes" onclick="doInputs(this);" tabindex="20">Send Email </div></td></tr>
<div id="hidden_divX" style="float: left; display:none; ">
<?php
$dept = $_SESSION['dept_id'];
$get_email = mysql_query("Select email_name, dept_id, copy_user from emails where escalated != 'yes'");
while(($email = mysql_fetch_assoc($get_email)))
{
$department = explode(",", $email['dept_id']);
if(in_array($dept, $department, TRUE))
{
echo '
<input type="checkbox" name="emailed_to[]" id="emailed_to[]" value="'.$email['email_name'].'" />'.$email['email_name'].'
';
if($email['copy_user'] == 'YES')
{
echo '
<input type="text" name="emails[]" style="width: 175px; height: 20px;" placeholder="To:">
';
}
}
}
?>
</div>
</form>

If you need to disable a checkbox by Javascript, you just need one line:
document.getElementById("foo").setAttribute("disabled","disabled")
and to enable it again,
document.getElementById("foo").removeAttribute("disabled")
I don't think you need to use jQuery for such task...
Good luck!

Related

Set a specific Time duration for page

I would like to specify the duration of the display of a form. Suppose there is a variable with the value x=(10), whenever I call this page, the timer should be based on the current time and the form should be displayed for 10 minutes and after this time the form should be sent automatically.
<?php
include 'db_conn.php';
if (isset($_GET['id'])) {
$var=$_GET['id'];
$query="SELECT * FROM addquiz WHERE quz_id='$var' ";
$db=mysqli_query($conn,$query);
$res=mysqli_fetch_array($db);
$noquestions=$res['noquestion'];
$quiz=$res['title'];
}?>
<div class="container">
<form method="POST" class="form-horizontal" >
<div style="margin-left: 30%;"><b>Your Quiz: <?php echo $quiz;?></b>
<input type="text" name="user_name" placeholder="Enter Your Name" style="height: 30px; width: 30%;"></div>
<div class="row">
<div class="col-md-12">
<div class="panel" style="margin:5%">
<?php
$count=1;
$que="SELECT * FROM addques WHERE quz_id='$var'";
$dbd=mysqli_query($conn,$que);
while ($cmd=mysqli_fetch_array($dbd)) {
$quest=$cmd['qusname'];
$ans_id=$cmd['ans_id'];
$opt1=$cmd['qpta'];
$opt2=$cmd['optb'];
$opt3=$cmd['optc'];
$opt4=$cmd['optd'];
$answ=$cmd['answer'];?>
<b>Question <?php echo $count++;?> :<br><?php echo $quest;?></b><br><br>
<fieldset>
<input type="hidden" name="ansid[]" value="<?php echo $ans_id; ?>">
<input type="checkbox" name="ans[]" value="1"><?php echo $opt1;?><br><br>
<input type="checkbox" name="ans[]" value="2"><?php echo $opt2;?><br><br>
<input type="checkbox" name="ans[]" value="3"><?php echo $opt3;?><br><br>
<input type="checkbox" name="ans[]" value="4"><?php echo $opt4?><br><br><br>
</fieldset>
<?php } ?>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
<div class="button" style="margin-left: 60%;"> View Result </div>
</div>
</div>
</div>
<?php
$i=0;
if (isset($_POST['submit'])) {
$name=$_POST['user_name'];
while ( $i<$noquestions ) {
$query="INSERT INTO `result`( `quz_id`, `ans_id`, `answer`,`user_name`) VALUES('";
$query.=$var . "', '";
$query.=$_POST['ansid'][$i] . "', '";
$query.=$_POST['ans'][$i] . "', '";
$query.=$name . "' )";
$db=mysqli_query($conn,$query);
$i++;
}
}
?>
It depends on what you are trying to achieve.
As you say "at each visit of the page" it could be done like this with javascript:
window.onload = function () {
window.setTimeout(function () {
document.form.submit();
}, 5000);
};
Further you could set the timeout from your php variable and like the comment says above, you could validate the taken time on the server side with php to make sure no one is cheating.

When Clicked edit button, corresponding details must be filled to the form for edit

I have a form which can submited.and have list,that listed all submited form details.
I tried it in different ways.I want to fill the form with the corresponding details when I clicked the edit button.
Here is my php file
<div class="row">
<div class="col-sm-9">
<b>Leader Name : </b><?php echo($row["lead_name"]); ?><br>
<b>Phone Number : </b><?php echo($row["phone_number"]); ?><br>
<b>Email : </b><?php echo($row["email"]); ?><br>
<b>Part Created Time : </b><?php echo($row["create_date_and_time"]); ?>
<br>
</div>
<div class="col-sm-3 ">
<form role="form" action='index.php' method='POST'>
<input type='hidden' name='party_id' value='<?php echo($row["party_id"]); ?> '>
<input type="submit" class="btn btn-sm btn-success btn-block" id="edit" name="edit" value="Edit" style="font-size: 12px; padding: 3px;">
<input type="submit" class="btn btn-sm btn-danger btn-block" id="delete" name="delete" value="Delete" style="font-size: 12px; padding: 3px;">
</form>
<?php
if (isset($_POST['delete'])) {
print("<script> alert('delete'); </script>");
$party_id = isset($_POST['party_id']) ? $_POST['party_id'] : "";
$queryDelete = "DELETE FROM party_details WHERE party_id='$party_id'";
if ($conn->query($queryDelete)) {
$_SESSION['party'] = "";
$_SESSION['trips'] = [];
print("<script>
alert('Party removed');
window.location.href='../tripCreate';
</script>");
} else {
print("<script>alert('Error when remove ! ');</script>");
}
$_POST = array();
}
if (isset($_POST['edit'])) {
$party_id1 = isset($_POST['party_id']) ? $_POST['party_id'] : "";
$query1 = "SELECT * FROM party_details WHERE party_id='$party_id1'";
$result1 = $conn->query($query1);
$row1 = $result1->fetch_assoc();
}
?>
</div>
first of all, you should specify not only result you want to achieve, but also what kind of problem you are facing.
is it php error, or information not being displayed in resulted page?
one thing i spotted is that you got $row1 = $result1->fetch_assoc(); but in form you echo $row[] (instead of $row1[]), which i dont see being created anywhere.
also, did you try var_dump($row) in php and check its content (or $row1...)?

Trouble controlling the loops

If pressed delet , All images are deleted ,I do not want that.
I just want to delete one image.
$get_img = "SELECT * FROM img";
$run_img = mysqli_query($db,$get_img);
while ($row_img= mysqli_fetch_array($run_img)){
if (isset($_POST['delete'])){
$delete= "DELETE FROM img WHERE id = {$row_img['id']} ";
$query = mysqli_query ($db , $delete);
}
echo '
<div style="width:200px; height:200px; border: 5px solid red; margin:10px; float: right;">
<img src="images/'.$row_pro['c_img'].'" width="200" height="200" /><br />
<form action="get.php" method="POST">
<input type="submit" name="delet" value="delet" />
</form>
</div>
';
}
Just a little explain, we start talking Arabic because Mostafa is not good in english, so i wrote a little explain in English and Arabic below to help to help both languages users.
while($row_img = mysqli_fetch_array($run_img)){
//explain [1]
echo '
<div style="width:200px; height:200px; border: 5px solid red; margin:10px; float: right;">
<img src="images/'.$row_img['c_img'].'" width="200" height="200" /><br />
<form action="?" method="POST">
<input name="id" value="'.$row_img['id'].'" hidden><!-- //explain [2] -->
<input type="submit" name="delet" value="delet" />
</form>
</div>
';
}
if(isset($_POST['delet'])){
$id = intval($_POST['id']);//explain [3]
$delete= "DELETE FROM img WHERE id = '$id'";
$query = mysqli_query($db, $delete);
if($query){
echo 'Deleted Successfully!';
}
}
explain [1] Remove the query from inside while its bad to put it there
explain [2] Then i made a hidden input called id to get the id from it
explain [3] Make the hidden sent id to $id variable and intval it for more security, you can read about it
.
explain [1] اول حاجة شلت الكويري إلي انت كاتبها جوا ال while
explain [2] بعدين سويت زر مخفي مع كل صورة إسمه أي دي يعطينا الاي دي الخاص فيها
explain [3] بعدين بستقبل الاي دي إلى بالزر المخفي على متغير جديد وبسويله شوية حماية.
I hope this helps you :)
Grab your isset and delete query out of while
Something like that. I did not checked all details but maybe it's good for inspiration.
$get_img = "SELECT * FROM img";
$run_img = mysqli_query($db, $get_img);
while ($row_img = mysqli_fetch_array($run_img))
{
echo '<div>
<img src="images/' . $row_pro['c_img'] . '" /><br />
</div>';
}
echo '<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="delete" value="delete" />
</form>';
if (isset($_POST['delete']))
{
$delete= "DELETE FROM img WHERE id = :id", ['id'=>$row_pro['id']];
$query = mysqli_query($db, $delete);
}
Hope you'll figured out.

PHP Dropdown Menu from DB column values

WHAT I STARTED WITH
My php
<?php
mysql_select_db("$db") or die(mysql_error());
$sql = "SELECT kpi FROM pin_kpi_types";
$query = mysql_query($sql);
echo '<select name="KPI" style="width: 400px">';
while ($row = mysql_fetch_assoc($query)) {
echo '<option>'.$row['KPI'].'</option>';
}
echo '</select>';
?>
My current label/input method that requires me to manually type.
What I am trying to do is pull a query from a table to select the only available KPI types.
This is working now.
<p>
<label for="KPIType" id="preinput">Choose KPI Type: </label>
<input type="text" name="kpi_type" required placeholder="Lead" id="inputid" />
</p>
WHERE I WAS AT PREVIOUS
Edit; Unfortunately the answer posted by Lucky didn't quiet help me, but it steered me in the right way.
I am now have duplicate fields? It isn't posting the value into the DB. either.
Here is a screenshot...
http://s30.postimg.org/o1c2l9yr5/Untitled.png
Can someone steer me in right direction of where I went wrong? :)
Thank you in advance for any help.
<?php
include('db.php');
$select=mysql_query("SELECT * FROM pin_kpi_types");
$i=1;
while( $userrow=mysql_fetch_array($select) )
{
$kpi_id =$userrow['KPI_ID'];
$kpi =$userrow['KPI'];
?>
<style>
#CreateStatusTypeFORM label {display: inline-block;width: 10em; text-align: right;padding-right: 0.5em;}
</style>
<div id="CreateStatusTypeFORM">
<form action="insert.php" method="post" name="insertform">
<p>
<div align='center'><label for="StatusColor" id="preinput">Choose A Color: </label>
<ui-colorpicker ng-model="targetColor"></ui-colorpicker></div>
<input type="hidden" name="pinstatus_color" value="{{targetColor}}" id="inputid" />
</p>
<p>
<label for="StatusName" id="preinput">Set Status Name: </label>
<input type="text" name="pinstatus_type" required placeholder="Come Back" id="inputid"/>
</p>
<p>
<label for="StatusName" id="preinput">Available KPI Types: </label>
<select name="<?php echo $kpi; ?>" style="width: 237px">
<option name="KPI" required id="inputid" value="<?php echo $kpi; ?>"><?php echo $kpi; ?></option>
</select>
</p>
<?php } ?>
<input type="submit" name="send" value="Submit" id="inputid1" />
</p>
</form>
WHERE I AM AT NOW
This is where I am at. I now can get the dropdown correct without duping it over and over. However, now I cannot get the value to post the actual selected KPI to the DB. everything else submits data to the db, but KPI_type option.
<style>
.StatusForm {padding-left:75px;}
.CreateStatusTypeFORM {padding:25px;border-style:solid; border-color:solid black; width: 500px;background-color:#C4C4C4;}
#CreateStatusTypeFORM label {display: inline-block;width: 100em;}
#CreateStatusTypeFORM input {border-color:solid black;}
#CreateStatusTypeFORM input[type=text] {padding:5px; border:1px solid #666; -webkit-border-radius: 5px; border-radius: 5px;}
</style>
<div class='StatusForm'>
<div class="CreateStatusTypeFORM">
<H3> ADD New Status </H3>
<form action="insert.php" method="post" name="insertform">
<p>
<label for="StatusColor" id="preinput">Choose A Color: </label>
<ui-colorpicker ng-model="targetColor"></ui-colorpicker>
<input type="hidden" name="pinstatus_color" value="{{targetColor}}" id="inputid" required placeholder=""/>
</p>
<p>
<label for="StatusName" id="preinput">Set Status Name: </label>
<input type="text" name="pinstatus_type" required placeholder="" id="inputid"/>
</p>
<p>
<label for="KPI" id="preinput">Available KPI Types: </label>
<select>
<?php
include('db.php');
$select2=mysql_query("SELECT * FROM pin_kpi_types ORDER BY KPI_ID DESC");
while( $userrow=mysql_fetch_array($select2) )
{
$kpi =$userrow['KPI'];
$kpi_id =$userrow['KPI_ID'];
?>
<option name="kpi_type" required id="inputid" value="<?php echo $kpi; ?>"><?php echo $kpi; ?></option><?php } ?>
</select>
</p>
<input type="submit" name="send" value="Submit" id="inputid1" />
</p>
</form>
</div>
</div>
This is the insert function.
<?php
ob_start();
include("db.php");
if(isset($_POST['send'])!="")
{
$pinstatus_type =mysql_real_escape_string($_POST['pinstatus_type']);
$kpi_type =mysql_real_escape_string($_POST['kpi_type']);
$pinstatus_color =mysql_real_escape_string($_POST['pinstatus_color']);
$update =mysql_query("
INSERT INTO pin_status_types(
pinstatus_type,
kpi_type,
pinstatus_color,
created
)
VALUES(
'$pinstatus_type',
'$kpi_type',
'$pinstatus_color',
now()
)
");
if($update)
{
$msg="Successfully Updated!!";
echo "<script type='text/javascript'>alert('$msg');</script>";
header('Location:index.php');
}
else
{
$errormsg="Something went wrong, Try again";
echo "<script type='text/javascript'>alert('$errormsg');</script>";
}
}
ob_end_flush();
?>
mysql_select_db("$db") or die(mysql_error());
$sql = "SELECT kpi FROM pin_kpi_types";
$query = mysql_query($sql);
echo '<label for="KPIType" id="preinput">Choose KPI Type: </label>';
echo '<select name="KPI" style="width: 400px" required id="inputid">';
echo '<option value=''>Lead</option>';
while ($row = mysql_fetch_assoc($query)) {
echo '<option value='.$row['KPI'].'>'.$row['KPI'].'</option>';
}
echo '</select>';
<?php
include 'config.php';
$sql_states=mysqli_query($conn,"SELECT * FROM master_states");
?>
<section Name="state_name">
<option value="">section1</option>
<option value="">section2</option>
</section>

How to make search results appear on another page?

I have a big search on my home-page and when the user types in the text fields and clicks submit I want the results from my database to appear on another site in this case 'searchresults.php.' In this case 'really.html' is my homepage.
Here is my code:
What am I doing wrong?
Really.html
<center>
<form action="searchresults.php" method="post">
<input type="text" size="35" value="Job Title e.g. Assistant Manager"
style="background- color:white; border:
solid 1px #6E6E6E; height: 30px; font-size:18px;
vertical-align:9px;color:#bbb"
onfocus="if(this.value == 'Job Title e.g. Assistant Manager'){this.value =
'';this.style.color='#000'}" />
<input type="text" size="35" value="Location e.g. Manchester"
style="background- color:white; border:
solid 1px #6E6E6E; height: 30px; font-size:18px;
vertical-align:9px;color:#bbb"
onfocus="if(this.value == 'Location e.g. Manchester'){this.value =
'';this.style.color='#000'}" />
<input type="image" src="but.tiff" alt="Submit" width="60">
</form>
Searchresults.php
<html>
<body>
<?php
if(strlen(trim($_POST['search'])) > 0) {
//all of your php code for the search
$search = "%" . $_POST["search"] . "%";
$searchterm = "%" . $_POST["searchterm"] . "%";
mysql_connect ("", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
}
$query = "SELECT name,location,msg FROM contact WHERE name LIKE '$search' AND
location LIKE '$searchterm'";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) {
echo "<br>$row[0]<br>";
echo "$row[1]<br>";
echo "$row[2]<br>";
}
}
}
?>
</body>
</html>
Thanks!
You should add attr name to your input.
For example,
<input type="text" name="search" ... />
<input type="text" name="searchterm" ... />
Also don't forget about escaping input data using mysqL_escape_string function
The query is probably returning 0 results. Instead of
if ($result) {
Try
if (mysql_num_rows($result) >= 1) {
And in your query try...
$query = "SELECT name,location,msg FROM contact WHERE name LIKE '%$search%' AND
location LIKE '%$searchterm%'";
This will be less strict and return a better result set.

Categories