Gian_Yagami Posted July 22, 2018 Share Posted July 22, 2018 Hello guys, I have a problem. I've started decision support web application. I am using loop for creating selection combo box and named it automatically. This is an example, but not my actual program because I am using my own language keywords: <?php $query = "SELECT name_criteria, id_criteria FROM criterias ORDER BY id_criteria asc"; $criteria = mysql_query($query); while ($resultcriteria = mysql_fetch_array ($kriteria)){ $index_criteria = $resultcriteria['id_criteria']; //id_criteria is integer and streak so I am using it for array indexing $name_criteria[$index_criteria] = $resultcriteria['name_criteria']; } for($index=0; $index <= $index_criteria; $index++) { ?> <div class="form-group"> <label class="col-sm-2 control-label text-right"><?php echo $name_criteria[$index] ?>:</label> <div class="col-sm-3"> <select name="<?php echo $name_criteria[$index] ?>" data-placeholder="Select" class="required select"> <?php $query = "SELECT * FROM compilation where id_criteria='$index' order by id_compilation asc"; $result = mysql_query($query); while ($data = mysql_fetch_array($result)) { echo "<option value='".$data['id_compilation']."'>".$data['name_compilation']."</option>"; } ?> </select> </div> </div> <?php } ?> I am using this post method <?php if (isset($_POST['save'])) { for($index=0; $index<=$index_criteria; $index++){ $id_employee = $_POST['id_employee']; $id_compilation = $_POST[$name_criteria[$index]]; //that thing is never changed, I always get value 0 no matter which box I choose. zero is the first id compilation $sql = "insert into classification values ('','$id_employee','$id_compilation')"; $query = mysql_query($sql) or die(mysql_error()); if ($query && $index>$index_criteria) { echo "<script>window.alert('Employee classification success!'); window.location=(href='classification.php')</script>"; } } ?> compilation has id_criteria in column witch means that thing has relation to criteria table. but I never successful when I used $_POST variable through another variable. Using single quote is really painful because I had many selection or combo box here. Because Selection/Combobox always increased during times and it based how much compilation available in the table. Link to comment Share on other sites More sharing options...
K^2 Posted July 24, 2018 Share Posted July 24, 2018 Am I reading this write that your first snippet is where you generate the form and perform the POST, and second snippet is responding to the POST? In that case, why do you expect the $name_criteria variable to carry over from first invocation to the second? Prior to filing a bug against any of my code, please consider this response to common concerns. Link to comment Share on other sites More sharing options...
Gian_Yagami Posted July 24, 2018 Author Share Posted July 24, 2018 (edited) 5 hours ago, K^2 said: Am I reading this write that your first snippet is where you generate the form and perform the POST, and second snippet is responding to the POST? In that case, why do you expect the $name_criteria variable to carry over from first invocation to the second? Because that was in same file. I was changed it to <select name="" data-placeholder="Select" class="required select"> so that I want to hook every variable of my selection combo box and that way isn't worked. Edited July 24, 2018 by Gian_Yagami incorrect color font Link to comment Share on other sites More sharing options...
K^2 Posted July 27, 2018 Share Posted July 27, 2018 Local variables aren't per-file. They are per execution of that file. If you have my_page.php submit a form to my_page.php, any variables you built up in the first execution of the script will not carry over when form is being processed. If you want to store variables that persist for a particular user, use session. Prior to filing a bug against any of my code, please consider this response to common concerns. Link to comment Share on other sites More sharing options...
Gian_Yagami Posted July 29, 2018 Author Share Posted July 29, 2018 On 7/28/2018 at 5:29 AM, K^2 said: Local variables aren't per-file. They are per execution of that file. If you have my_page.php submit a form to my_page.php, any variables you built up in the first execution of the script will not carry over when form is being processed. If you want to store variables that persist for a particular user, use session. I knew, but I am just use post method for getting which option is selected. And I can't figure it out. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now