I have two buttons on one submit form but when I post the submit button it returns nothing;"ABOUT THE BUTTON"; the other data is retrieved WELL.
I have been using different names for the submit button but nothing works.. Could someone help me? thank you.
The FORM data is retrieved well but not the submit button value? i need the value to differ the condition
controller: admin.php
function submit_unitgroupwd(){
$this->access_chk(); //CHECK USER ACCESS
$sbm=$this->input->post('sbm'); // returns NOTHING
echo $_POST["sbm"]; // returns undefined index sbm
echo $_POST['sbm']; // returns undefined index sbm
var_dump($_POST); // returns all the post data bt the submit button
//echo var_dump($this->input->post("sbm"));
exit();
if($this->input->post('sbm') == "Update") {
// do update
} else {
// do delete
}
}
view:
echo "<form action=".site_url("admin/submit_unitgroupwd")." method=post id=form>";
echo "<div style='float:left;color:red;' id='res'></div>";
?><?php
foreach($q1->result_array() as $r1){
$bankname= substr($r1["bank"],0,3);
//echo $bankname;
echo "<input type=hidden name=dgroup value='".$dgroup."'>";
echo "<tr>";
echo "<td width=20% colspan=3 style='font-size: 16px;'>".strtoupper($r1["bank"])."</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=100>".$group_[0]."</td>";
echo "<td><input type=text name='$bankname-utama' value='".str_replace(" ","",$r1["utama"])."' style='width: 100%;'></td>";
if ($r1["bank"] == 'ALL'){
echo "<td rowspan='1'><br><input type='checkbox' name='cek[]' id='cek[]' value='$bankname' ></td>";
echo "<input type=hidden name=_code$bankname value='".$r1["bank"]."'>";
echo "</tr>";
echo "</tr>";
continue;
}
echo "<td rowspan=".($dgroup + 1)."><br><input type='checkbox' name='cek[]' id='cek[]' value='$bankname' ><br><br><br><br><br><br><br>";
echo "<input type=hidden name=_code$bankname value='".$r1["bank"]."'>";
echo "</tr>";
$_alp = "a";
for ($_g=0; $_g<$dgroup; $_g++){
echo "<tr>";
echo "<td width=100>".$group_[($_g + 1)]."</td>";
echo "<td width=80%><input type=text name='$bankname-wd$_alp' value='".str_replace(" ","",$r1["wd$_alp"])."' style='width: 100%;'></td>";
echo "</tr>";
$_alp++;
echo "</tr>";
}
}
?>
>
<input type="submit" class="button" value='Update' name="sbm"/>
<input type="submit" class="button" value='Delete' name="sbm"/>
I'm not completely clear on your description of the problem, but you can't name both submit buttons the same.
You seem to think that push one or the other button will only submit THAT button's value, but in fact the second one is always submitted, because it is the last on the form.
So change your button names to "update" & "delete", and then you can check with
if(isset($_POST['update']))....
for example.
However, you might want to look around the internet for some cleaner examples of how to code what you are after.
You could simply use only the
<input type="submit" class="button" value='Update' name="sbm"/>
and use an anchor for the delete action,
echo "<a href ='controller_delete/$item_id' class='button'>Delete</a>
since you normally wont need other inputs on the delete action if you get my point.
Related
I'm trying to use jquery to click a link in one div and have it open an HTML document in another div (named infoblock) that sits beside the original div. I found an example here but I can't get it to work. I found a couple other variations on the net, but still no luck. Part of the link needs to transmit a variable so I'm not sure if that's part of the problem. I tried attaching the click function to a div surrounding the link with an ID of "nav" as well as the link itself with an ID of "details". When I click on the link, it opens the correct page in the full window, not in the div it's supposed to go to. Thank you in advance for any help.
$(document).ready(function() {
$("#reservename").click(function() {
$("#infoblock").load("createhandle.html");
});
$("#uploadpic").click(function() {
$("#infoblock").load("uploadpic.php");
});
$("#deletechar").click(function() {
$("#infoblock").load("selectdelete.php");
});
$("#nav").click(function() {
$("#infoblock").load($(this).find("a").attr("href"));
return false;
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="charlist" class="block">
<b>Your Characters:<b>
<br>
<button id="reservename">Reserve A Name</button>
<button id="uploadpic">Upload A Picture</button>
<button id="deletechar">Delete</button>
<?php
$result5 = mysqli_query($con,"SELECT * FROM handle WHERE user='$handle' ORDER BY charname ASC");
while($row = mysqli_fetch_array($result5))
{
echo "<table>";
echo "<tr>";
echo "<td rowspan=5 align=left><img src='../pictures/" . $row['face'] . "' border=3></td>";
echo "<th align=left><a href='chat.php?charname=" . $row['charname'] . "'>" . $row['charname'] . "</a></th>";
echo "</tr>";
echo "<tr>";
echo "<th align=left><a href='choosepic.php?charname=" . $row['charname'] . "'>Choose Picture</a></th>";
echo "</tr>";
echo "<tr>";
echo "<th align=left><div id='nav'><a id='details' href='../details.html?charname=" . $row['charname'] . "'>Details</a></div></th>";
echo "</tr>";
if ($row['type'] == 'new'){
echo "<tr>";
echo "<th align=left><a href='createsheet.php?charname=" . $row['charname'] . "'>Create</a></th>";
echo "</tr>";
}
echo "<hr>";
echo "</table>";
}
?>
</div>
<p id="infoblock" class="block"></p>
You have to prevent the default behaviour when anchor tag is clicked In order to do that that you have to be listen for click on the anchor itself not div and return false in order to prevent its default behaviour. So your code will become like this
$('#details').click(function(e){
{
e.preventDefault(); //instead of this you can also return false
$("#infoblock").load($('#details').attr("href"));
}
});
This works for me:
$(document).ready(function(){
$('#details').click(function(e){
e.preventDefault();
$("#infoblock").html('<object type="text/html" data="'+$('#details').attr("href")+'" >');
});
});
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>
I have seen some answers but I have not found anything that I want. I have a table with these rows:
while ($rown = mysql_fetch_assoc($resulti)){
echo "<tr style=text-align:center>";
echo "<td>".$rown['emri']."</td>";
echo "<td>".$rown['mbiemri']."</td>";
echo "<td>".$rown['dega']."</td>";
echo "<td>".$rown['id']."</td>";
echo "<td>".$rown['viti_shkollor']."</td>";
echo "<td><input type=text style= width:30px />"</td>";
echo "</tr>";
}
It works perfectly but I want to get the values of input type that user enters and then to put them in a mySql database. Also the table has a submit button as below so when the user completes all of the table inputs then press the submit and all of values go to the database.
<input type="submit" value="prano" name="prano" style="margin:0 auto;" />
It is difficult for me to get the value of input and to put it in a variable. I hope you understand my question. Please help me.
there are few points which you need to include:
1) add form in to your html
2) add name to all input box with in while
echo '<form action="test.php" method="post">';
while ($rown = mysql_fetch_assoc($resulti)){
echo "<tr style=text-align:center>";
echo "<td>".$rown['emri']."</td>";
echo "<td>".$rown['mbiemri']."</td>";
echo "<td>".$rown['dega']."</td>";
echo "<td>".$rown['id']."</td>";
echo "<td>".$rown['viti_shkollor']."</td>";
echo "<td><input name='custom[".$rown['id']."]' type=text style= width:30px />"</td>";
echo "</tr>";
}
echo "</form>";
So that now in test.php:
in $_POST[custom] you will get array of values of all input field custom.
Other users have had similar problems about when they're looping rows of buttons but it's always because they accidentally reused the same Id or value. I'm experiencing the same problem, but all of my buttons are unique.
AJAX request
<script>
$(document).ready(function(){
$("#friendadd").submit(function(){
alert("checkpoint");
$.ajax({
type:"POST",
url:"getuser.php"
});
})
});
</script>
PHP and form
<form id="friendadd">
<?php
for($i=0; $i<$ctk->rowCount(); $i++){
echo "<img src='".$ctk_values[$i][6]."' alt='Blank' style='width:64px;height:64px'>";//PP, Later add clickable profile
echo "<th rowspan='3'>Attributes</th>";
echo "<tr> ".$ctk_values[$i][0]."</tr>";//UN
echo "<tr> ".$ctk_values[$i][1]."</tr>";//UL
echo "<tr> ".$ctk_values[$i][5]."</tr>";//UA
?>
<input type="submit" id="friend<?php echo $i;?>"><!--pass in this.value-->
</form>
<?php
}//Ends for loop
}
}
?>
Explanation: When I type in a username into the search box, it returns me three different users named rikesh1, rikesh2, and rikesh3. Each of them have a button next to them, with values friend0, friend1, friend2, respectively. When I click on the friend0 button, it successfully calls and updates the database. When I click the friend1 button, nothing happens. This is different from other users in that my buttons have unique Ids. Thanks for any and all help, I think this is a very fixable problem but after searching Stack, I'm still not sure what's happening.
<form id="friendadd">
<?php
for($i=0; $i<$ctk->rowCount(); $i++){
echo "<img src='".$ctk_values[$i][6]."' alt='Blank' style='width:64px;height:64px'>";//PP, Later add clickable profile
echo "<th rowspan='3'>Attributes</th>";
echo "<tr> ".$ctk_values[$i][0]."</tr>";//UN
echo "<tr> ".$ctk_values[$i][1]."</tr>";//UL
echo "<tr> ".$ctk_values[$i][5]."</tr>";//UA
?>
<input type="submit" id="friend<?php echo $i;?>"><!--pass in this.value-->
<?php
}//Ends for loop
?>
</form>
<?php
}
}
?>
Use this code instead.
The other one ends the form tag at the first loop.
I haven't worked much with php and javascript and was hoping to get some help. I want to be able to detect which button was clicked exactly. I'm creating one button per row but I don't know how to figure out what row the click was made in. This is what I have so far...
# Get all the table data from the database
$getData = mysqli_query($conn, "SELECT * FROM `query_table`") or die ("Error occured while selecting!");
// echo '<form method="post" action="index.php">';
echo '<table border="1">';
echo '<tr>';
echo '<td>Questions</td>';
echo '<td>Likes</td>';
echo '<td></td>';
echo '</tr>';
# Loop through each row and print out the question
while ($row = mysqli_fetch_array($getData)) {
echo '<tr>';
echo '<td>';
echo $row['Question'];
echo '</td>';
echo '<td>';
echo $row['Likes'];
echo '</td>';
echo '<td>';
?>
<input type="button" id="myButton" value="Like" onclick="myFunc(<?=$row['ID']?>)" />
<?php
echo '</td>';
echo '</tr>';
}
echo '</table>';
// echo '</form>';
echo '<p id="text"></p>';
mysqli_close($conn);
?>
<script type="text/javascript">
function myFunc(id) {
document.getElementById("text").innerHTML = id;
}
</script>
So far this prints out the row id where the button was clicked, but I don't suppose I can assign that parameter value directly to a php variable that I can then use for mysql queries. How is stuff like this normally done, please help.
<input type="button" data-id="<?=$row['ID']?>" value="Like" onclick="myFunc(this)">
and
<script type="text/javascript">
function myFunc(button) {
document.getElementById("text").innerHTML = button.getAttribute('data-id');
}
</script>
In JavaScript the token "this" refers to the context in which the code is running which in this case is the button. Store custom data in attributes prefixed with data- to ensure they are not disturbed - standard practise.