I am new in coding. I started learn PHP and I got into a problem that I tried to catch the data from dropdown menu and print it inside the same code via PHP. But the problem is when I try to select it doesn't show anything. Please help!
<?php
if (isset($_POST['submit'])) {
$code = $_POST['coder'];
echo "You are ".$code." coder";
}
?>
<form action="" method="post" name="myForm" id="myForm">
<table>
<tr>
<td>Languages: </td>
<td>
<select name="coder">
<option>Select One</option>
<option value="JAVA">JAVA</option>
<option value="PHP">PHP</option>
<option value="C#">C#</option>
<option value="C++">C++</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value ="Submit">
<input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
isset($_POST['submit']) becoming false because there is no any element with name "submit". Try setting name to submit button as.
<input type="submit" value ="Submit" name="submit">
Related
I am trying to update some table rows (there can be 40-50 rows) generated from a MYSQL query with a Approve/Rejected column at the end of each row, I would like to use jQuery to update the row using a select dropdown, the problem I am having is that it only updates the first row.
I have tried to look at other Stackoverflow threads, there seems to be quite a few with similar issues, but I am still trying to get my head around jQuery so I couldn't work out how to do it.
I am guessing it's because of the same class names?
My HTML table/forms
<table>
<tr>
<td>1</td>
<td>Ren</td>
<td>
<form method="post" action="" class="dangermouse">
<div class="form-group">
<select name="approval" class="approval">
<option value="0">Approved</option>
<option value="1">Reject</option>
</select>
</div>
<input type="hidden" name="id" value="1">
<input type="button" name="updaterow" class="save_button" value="Update">
</form>
</td>
</tr>
<tr>
<td>2</td>
<td>Stimpy</td>
<td>
<form method="post" action="" class="dangermouse">
<div class="form-group">
<select name="approval" class="approval">
<option value="0">Approved</option>
<option value="1">Reject</option>
</select>
</div>
<input type="hidden" name="id" value="2">
<input type="button" name="updaterow" class="save_button" value="Update">
</form>
</td>
</tr>
</table>
jQuery:
$('.save_button').click(function() {
var approval = $('.approval').val();
var id = $('.id').val();
$('.save_status').text('loading...');
$.post('updateRow.php',{
approval: approval,
id: id
}, function(data) {
$('.save_status').text(data);
}
);
});
PHP File:
if(isset($_POST['approval'],$_POST['id'])) {
$approval = $_POST['approval'];
$id = $_POST['id'];
if($approval !="" && $id !="") {
$pdo->ApproveOrDeny($approval, $id);
} else {
echo "The same thing we do every night, Pinky - try to take over the world!";
}
}
Thanks in advance.
You need to access the clicked form values .instead of just using class name
1) Setup unique name for each form
2) Access the value using form name like this $('form[name="form1"]>.id').val()
$('.save_button').click(function() {
var form = $(this).parents('form:first').attr('name');
alert(form);
var id = $('form[name="'+form+'"]>.id').val();
var option =$('form[name="'+form+'"] .approval').val();
alert(id);
alert(option);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>1</td>
<td>Ren</td>
<td>
<form method="post" name="form1" action="" class="dangermouse">
<div class="form-group">
<select name="approval" class="approval">
<option value="0">Approved</option>
<option value="1">Reject</option>
</select>
</div>
<input type="hidden" class="id" value="1">
<input type="button" name="updaterow" class="save_button" value="Update">
</form>
</td>
</tr>
<tr>
<td>2</td>
<td>Stimpy</td>
<td>
<form method="post" name="form2" class="dangermouse">
<div class="form-group">
<select name="approval" class="approval">
<option value="0">Approved</option>
<option value="1">Reject</option>
</select>
</div>
<input type="hidden" class="id" value="2">
<input type="button" name="updaterow" class="save_button" value="Update">
</form>
</td>
</tr>
</table>
My code is very simple yet I cannot make a doPost request.
Here is my code below. I am using PHP 5.6.25 or PHP 7.0.10 im not sure. I just recently installed wampp
<?php
include('db.php');
if(isset($_REQUEST['btnsave']))
{
echo "Saves"; //This is not showing after clicking save
}
?>
<form action="" method="post">
<table>
<tr>
<td> Student </td>
<td><input type="text" name "txtsu_name"> </td>
</tr>
<td>Address</td>
<td><input type="text" name "txtaddress"> </td>
</tr>
<td>Status</td>
<td>
<select>
<option value ="1"> Active </option>
<option value ="0"> Suspend </option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Save" name"btnsave"> </td>
</tr>
</table>
</form>
You pretty missing all equal sign in name properties not just bntsave
name="anything"
So, please update all input fields.
and add name to select also:
<select name="isActive">
The following is my HTML. I want to pass the name of the dropdownlist(d1and d2) to another survey.php page when the button is clicked.
<!DOCTYPE html>
<head>
<title>Survey</title>
</head>
<body>
<form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
<td height=" 30" width="200">
Condition of the item received:
<select name="d1">
<option>Select One</option>
<option value="g">Good</option>
<option value="s">bad</option>
<option value="u">Worst</option>
</select>
</td>
<td height=" 30" width="200">
Price of the Item:
<select name="d2">
<option>Select One</option>
<option value="g">Good</option>
<option value="s">bad</option>
<option value="u">Worst</option>
</select>
</td>
</tr>
<tr>
<td align="center" >
<input type="button" name="submit1" value="Submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
Rewrite:
<form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
<td height=" 30" width="200">
Condition of the item received:
<select name="d1">
<option>Select One</option>
<option value="Good">Good</option>
<option value="bad">bad</option>
<option value="Worst">Worst</option>
</select>
</td>
<td height=" 30" width="200">
Price of the Item:
<select name="d2">
<option>Select One</option>
<option value="Good">Good</option>
<option value="bad">bad</option>
<option value="Worst">Worst</option>
</select>
</td>
</tr>
<tr>
<td align="center" >
<input type="button" name="submit1" value="Submit" />
</td>
</tr>
</table>
</form>
Firstly, instead of: <input type="button" name="submit1" value="Submit" />
Use: <input type="submit" name="submit1" value="Submit" />
<input type="submit"> is what is used to actually send the form.
Secondly, in the body of survey.php:
<?php
echo "You rated ".$_POST['d1']." for condition."
echo "You rated ".$_POST['d2']." for price."
?>
In short:
The $_POST variable in PHP is automatically set to a dictionary containing all the POST parameters.
I have a dropdown where user select some values and moves to other dropdownlist in sorted order by javascript. How can I get the chosen value in second dropdownlist in next page to a PHP variable ?
<form name="Example" action="next.php" method="post">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>
<select name="Features" size="9" MULTIPLE>
<option value="2">Row 2</option>
<option value="4">Row 4</option>
<option value="5">Row 5</option>
<option value="6">Row 6</option>
<option value="7">Row 7</option>
<option value="8">Row 8</option>
<option value="9">Row 9</option>
</select>
</td>
<td align="center" valign="middle">
<input type="Button" value=">>" style="width:100px" onClick="SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)">
<br>
<input type="Button" value="<<" style="width:100px" onClick="SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)"><br>
<input type="Button" value=">>>>" style="width:100px" onClick="selectAll(document.Example.Features);SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)"><br>
<input type="Button" value="<<<<" style="width:100px" onClick="selectAll(document.Example.FeatureCodes);SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)">
</td>
<td>
<select name="FeatureCodes[]" id="FeatureCodes" size="9" MULTIPLE>
<option value="1">Row 1</option>
<option value="3">Row 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="submit" id="submit" name="submit"></td>
</tr>
</table>
Thanks in advance!!
The value of the selected element in your second form field should be in:
$_POST['FeatureCodes'][0];
If you only have one FeatureCodes form on the page then you can remove the [] from your HTML and access it using $_POST['FeatureCodes'];
<div id="form1" />
<form name="choice">
<table>
<tr>
<td>
Number of new types you want to add
</td>
<td>
<select name="<?php echo $num; ?>">
<option value="1" selected>1 row</option>
<option value="2">2 rows</option>
<option value="3">3 rows</option>
<option value="4">4 rows</option>
<option value="5">5 rows</option>
</select>
<div class='inputs'></div>
</td>
</tr>
</table>
</form>
<form name="myForm" action="addAccessories.php" method="post" onsubmit="return validateForm(this);">
<table border="1">
<tr>
<th>Barcode<em>*</em></th>
<th>Description<em>*</em></th>
<th>Minimum required stock<em>*</em></th>
<th>Current stock</th>
</tr>
<?php
echo $num;
?>
<tr>
<td><input type="text" name="bar_code/></td>
<div class="ui-widget">
<td><input name="description/></td>
</div>
<td><input type="text" name="minimum_required_stock" /></td>
<td><input type="text" name="num_stock" value="0"></td>
<tr>
<td> </td>
<td> <button data-theme="b" id="submit" type="submit">Add accessories</button></td>
</tr>
</table>
</form>
Hello guys,
In this code I have 2 form, 1 is the drop box has 5 options and a form for text input.
In theory, if I choose option value="3", the text form will be loop 3 times and get 3 set of text inputs. However, I haven't succeeded in doing this by far. And also, how can I access these 3 sets of data in addAccessories.php file?
I appreciate any opinion on this topic.
Thank you very much.
Reading your question, it sounds like you want to have code such that when the selection in form choice changes, you change the number of rows in form myform. This is not possible from php because it will be a runtime change on the client machine. You can write this in javascript. You will need code called from form choice that adjusts the DOM in form myform.
You can either use a pure PHP solution and rebuild the page - but that's clunky and slow (which, might be fine for a pet project). Normally we'd use Javascript with AJAX to accomplish something like this.