Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Form won't post

  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form won't post

    So I am working on a greenhouse game. This page searches the user inventory for all lights and displays them in a table with a simple text box (later to be changed to hidden but for debugging purposes this does the job) that holds the lightid for selecting. Upon clicking the image of the item in question, it copies the lightid from the position box to the selected box.

    All this works fine

    However, when I click submit, the form merely resets itself and no actions are taken. I added a little 'print "this has posted" just beneath the if($_post) to check if the ($_post) was going through or not, it doesnt appear to be. I have tried moving the if($_POST) to the top, above the light inventory generation but was still unsuccessful

    help...

    Code:
    <?php
    
     //dbase connecting code and userid retrieval goes here
    //Connect to Dbase and get inventory of lights and place into cookie for retrieval and display later on (this works fine)
    
    
    	if($_POST)
    	{
                          print "this has posted";
    		$lighttoadd = $_POST['selected'];
    		if (isset($_SESSION['temppos'])
    		{
    			$pos = ((int)$_SESSION['temppos']);
    		}
    		else
    		{
    			$pos=0;
    		}
    		//If position is known, update position
    		if($pos!=0)
    		{
    			
    			$query = "UPDATE player_flower_lights SET lightid = '$lighttoadd' WHERE playerid = '$user' AND lightpos = '$pos'";
    			$result = mysql_query($query);
    		}
    		else
    		//if position unknown, check if position is available and add to end
    		{
    			//getnumlights + 1 = lightposition
    			$playerlights = array();
    			$maxlights = 0;
    
    			$query = "SELECT * FROM player_flower_lights WHERE playerid = '$user'";
    			$result = mysql_query($query);
    			while($result)
    			{
    				$row = mysql_fetch_assoc($result);
    				$playerlights[]=$row['lightpos'];
    			}
    			$numlights = count($playerlights);
    			$nextpos = $numlights + 1;
    
    			//getmaxlights
    			$query = "SELECT environmentid FROM player_env_hardware WHERE playerid = '$user'";
    			$result = mysql_query($query);
    			if($result)
    			{
    				$row = mysql_fetch_assoc($result);
    				$envid = $row['environmentid'];
    			
    				$query = "SELECT maxlights FROM environment WHERE id = '$envid'";
    				$result = mysql_query($query);
    				if($result)
    				{
    					$row=mysql_fetch_assoc($result);
    					$maxlights = $row['maxlights'];
    				}
    				else
    				{
                    	print "Error loading maxlights";
    					$success = 0;
    				}
    			}
    			else
    			{
            			print "Error loading environment";
    					$success = 0;
    			}
    			if($nextpos<=$maxlights)
    			{
                                                //if a position is available, insert into the players dbase of lights at the next available position
    				$query = "INSERT INTO player_flower_lights (playerid, lightid, lightpos) VALUES ('$user', '$lighttoadd', '$nextpos')";
    				print "Light successfully added to player database";
    				$result = mysql_query($query);
    				
    				$query = "SELECT lumens, tempmod FROM lights WHERE id = '$lighttoadd'";
    				$result = mysql_query($query);
    				$lumens=0;
    				$tempmod=0;
    				if($result)
    				{
                                                           //get light stats
    					$row = mysql_fetch_assoc($result);
    					$lumens = $row['lumens'];
    					$tempmod = $row['tempmod'];
    				}
    				else
    				{
    					print "Error retrieving light stats";
    				}
    		
    				//update room stats with new light stats
    				//get current room stats
    				if($lumens !=0)
    				{
    				$totallumens = 0;
    				$totaltempmod = 0;
    				$query = "SELECT totallumens, tempmod FROM player_env_stats WHERE playerid = '$user'";
    				$result = mysql_query($query);
    				if($result)
    				{
                                                           //get current room stats
    					$row = mysql_fetch_assoc($result);
    					$totallumens = $row['totallumens'];
    					$totaltempmod = $row['tempmod'];
    					$totallumens += $lumens;
    					$totaltempmod += $tempmod;
    			                     
                                                          //update stats
    					$query = "UPDATE player_env_stats SET totallumens = '$totallumens' WHERE playerid = '$user'";
    					$result=mysql_query($query);
    			
    					$query = "UPDATE player_env_stats SET tempmod = '$totaltempmod' WHERE playerid = '$user'";
    					$result=mysql_query($query);
    		
    			//remove item from inventory
    					$query = "DELETE FROM player_inventory WHERE itemid = '$lighttoadd' AND UCASE(itemtype) = 'LIGHTS' AND playerid = '$user'";
    					$result = mysql_query($query);
    				}
    				else
    				{
    					print "Error connecting to environment statistics";
    				}
    			}
    			else
    			{
    				print "All light positions full";
    			}
    		}
    		}
    	}
    		
    
    ?>
    	
    	<html>
    	<head>
    	<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
    	<meta http-equiv='Content-Script-Type' content='text/javascript'>
    	</head>
    	<body>
    	
    	<?php
    	
    	print "<table id='inventory' border=1>";
    	print "<tr>";
    	
    	//step2 display all lights (from cookie) in table with onclick that selects clicked item (hidden form item)
    	$numitems = $_COOKIE['numitems'];
    	
    	for ($i=0;$i<=$numitems-1;$i++)
    	{
    		$cookieid = 'lightarray'.($i+1);
    		$lightid = $_COOKIE[$cookieid];
    		print "<td id = 'invbox".($i+1)."' >";
    		print "<form id='lightarray".($i)."'>";
    		print "<img src = 'images/Lights/".$lightid."inv.jpg' onclick=\"selectedpos.selected.value=lightarray".($i).".position".($i+1).".value\">";
    		print "<input type = 'text' id = 'position".($i+1)."' value='".$lightid."'>";
    		print "</form>";
    		print "</td>";
    	}
    	print "</tr>";
    	print "</table>";
    	
    ?>	
    	
    	<form id='selectedpos' method='POST' action='addflowerlight.php'>		
    	<input type ='text' id='selected'>
    	<input type ='submit' value='Equip Light'>
    	</form>
    	</body>
    	</html>
    Last edited by schenn; 12-26-2010 at 11:46 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    What is the name of the script you are showing us.
    Always provide the filename when you post a script.

    As far as I know, "addflowerlight.php" is a script you aren't showing us.



    .

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is addflowerlight.php

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    This form ....

    <form id='selectedpos' method='POST' action='addflowerlight.php'>
    <input type ='text' id='selected'>
    <input type ='submit' value='Equip Light'>
    </form>


    Has no variable names ... how is it supposed to work?

    "id" is not a variable name.

    Maybe you meant to do this?

    <form id='selectedpos' method='POST' action='addflowerlight.php'>
    <input type ='text' name='selected' id='selected'>
    <input type ='submit' name='submit' value='Equip Light'>
    </form>


    .... and this line:
    if($_POST)

    would become:
    if($_POST['submit'])

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you.

    cant believe I missed that...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •