Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Updates
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

PHP getting selection/combobox value by using post method


Gian_Yagami
 Share

Recommended Posts

Gian_Yagami

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

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

Gian_Yagami
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 by Gian_Yagami
incorrect color font
Link to comment
Share on other sites

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

Gian_Yagami
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.