Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Here I have 10 input field. Then when the user click submit button I want the only input field that have been modify send to database and update rather than all input field sent to the database.
How can I achieve it?
If you need to save the fields that the user touched, see the first variant. But a downside is that if the user changed the filed "abc" to "xyz" and then changed it to "abc", then the field will be marked as changed. If this is not what you want, then see the next variant.
(1)
You can use onchange() event in your field to set a variable when the field is modified. Then send these variables to the server using input hidden fields. Like this:
<input type='text' name='input1' onchange="getElementsByName('input1changed')[0].value = 1;">
<input type='text' name='input2' onchange="getElementsByName('input2changed')[0].value = 1;">
<input type='hidden' name='input1changed' value=0>
<input type='hidden' name='input2changed' value=0>
Then in your PHP code:
if ($_POST['input1changed'])
store $_POST['input1']
if ($_POST['input2changed'])
store $_POST['input2']
(2)
<input type='hidden' name='input1old' value='sometext1'>
<input type='text' name='input1' value='sometext1'>
<input type='hidden' name='input2old' value='sometext2'>
<input type='text' name='input1' value='sometext2'>
and in PHP:
if ($_POST['input1old'] != $_POST['input1'])
store $_POST['input1']
if ($_POST['input2old'] != $_POST['input2'])
store $_POST['input2']
You can compare the 2 arrays.
The first one is the data you loaded on the website and the second one the $_POST array.
You can check in your php if the input is set and write a query accordingly.
if(isset($_POST['name'])){
<!-- query -->
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Assigning GET for some fields and assigning POST for other files in the same form. Is it possible?
if you have Specified data for get method you can use by this
<form method="POST" action="form.php?a=1&b=2&c=3">
.........
.........
</form>
And if you want PHP GET and POST simultaneously via single HTML form Read this documentation.
This
HTML 5 lets you mix methods by using the formmethod attribute:
<form method='POST'>
<button formmethod='GET' name='foo' value='qux' type='submit'>Get</button>
<input type='hidden' name='bah' value='humbug'>
<input type='submit' name='bar' value='Post'>
</form>
Which allows you to submit the same form via POST or GET for example.
However, having one text input being submitted under POST and another under GET at the same time is not doable.
A form will only be submitted under one http method at a time. In Php you can check that via $_SERVER['REQUEST_METHOD'].
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
First off, I know that there is deprecated code in my example, I'm working with a platform I designed a while ago and have not yet finished updating it all to use mysqli instead, so I'm making some minor edits to the existing platform.
So I have a form that creates inputs based on categories inputted in a different table, the form outputs correctly but repeats the same name (points and cat) for each category that exists.
According to another post (How to insert the dynamic table row data into database at once) inserting this data into my table can be accomplished with a for loop as shown in my example.
The issue I'm having is that it's only firing once, despite the fact that the array it creates should have 4 inputs. Also, the data that is being sent to the table column "cat_id" is "3" which could either be the first digit of the cat_id it's using, or the last array iteration [0], [1], [2], [3].
This is my first question, so I apologize if all the details needed are not provided, I will gladly update if anything else is needed.
$cat_id = $_POST['cat'];
$points = $_POST['points'];
$count = count($cat_id);
for ($i = 0; $i < $count; $i++) {
$sql = "INSERT INTO scoring (cat_id, points) VALUES ('$cat_id[$i]','$points[$i]')";
$query = mysql_query($sql);
}
EDIT: Updated code based on suggestions.
The question/answer you linked are incorrect. Arrays are not built dynamically by default in HTML:
To get your <form> result sent as an array to your PHP script you name the <input>, <select> or <textarea> elements like this:
<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyArray[]" />
http://php.net/manual/en/faq.html.php#faq.html.arrays
So I presume you currently have
<input name="cat">
<input name="cat">
which will only process as one cat element. This causes your 1 iteration.
Try:
<input name="cat[]">
for each field. To debug this in the future use print_r or var_dump to output what you think a variable contains.
Also use mysql_real_escape at a minimum while you update your driver to something that can handle parameterized queries.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I basically want to create a simple text input with a button that says submit. And using PHP I want to be able to give a different answer based on what the users input was. For example, if the user inputs the number 6, I want it to display "You are on week 6" - Can someone help me? I am having some trouble putting this together to get it to work.
The simple version is something like this:
<?php
echo "You are on week".$_POST['week'];
Your form would look like:
<form method="post">
<input name="week" />
<input type="submit" value="Submit" />
</form>
But it's much more complicated than this; you have to validate the input and worry about injection attacks, among other things.
You will get better help on here if you provide some code that you already have in place and ask specific questions about particular problems.
When your form is
<form method="post">
<input name="nameOfYourInput"/>
<input type="submit" value="sendButton"/>
</form>
This doesn't depend on serverside language be it php or any other language.
Specific to php is only the printing of the variable in the input field.
which can be achieved by
<?php
echo "You are on week" . $_POST['nameOfYourInput'];
The $_POST is variable which is passed(automaticaly) to the server with the http request.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
<form name="form11" method="post" action="hpdata.php" enc type="multipart/form-data">
<input name="pro" id="pro" type="hidden" value= "CMS" />
<input name="piror" id="piror" type="hidden" value= "P1" />
<input name="stat" id="stat" type="hidden" value= "In Progress" />
<input type="submit" name="submit" id="submit" class="groovy button" value="...">
</form>
in this code I can't see the data
hidden attribute just use for hide item from the UI. but still you can acsess them after form is submitted using $_POST['id here'] (if form method is get you should get it through $_GET[])
the code you provided has nothing to do with mysql.
It is a html fragment. It contains hidden inputs. If you want to make them visible remove type="hidden".
But most likely there is a purpose why they are hidden. Often this is done to keep values for different form pages or to present the user with pretty values, but send easier to handle versions to the server. (e.g. dates can have different formats in different countrys, but its easier to just send them in a standardized form --> this one would be in a hidden input.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a php form with dynamic checkboxes. It must connect to sql server and get their count and names. At the end I want submit the checked boxes.
example
I get from db some vegetables, for a receipt, and add checkboxes in my form. The user will check some of the and submit it.
I can't make <input type=checkbox id=...> because when post it i will not know the names of them. For that reason, i made a js function and when a checkbox checked, i add it to a array.
Now i want ask you, how i can submit this array and after that get the values at post.php file?
Create your checkboxes like:
<input type="checkbox" name="veg[]" value="tomato">
<input type="checkbox" name="veg[]" value="lettuce">
<input type="checkbox" name="veg[]" value="carrot">
<input type="checkbox" name="veg[]" value="celery">
Even if you don't know the names, you can iterate through the checkbox using:
<?PHP
foreach($_POST["veg"] as $veg){
echo $veg;
}
?>
Have you added name attributes to your checkboxes? Like so:
<input type="checkbox" name="potatoes" />