Page 1 of 1

$_POST form data question [Resolved]

Posted: Sat Nov 27, 2010 8:52 pm
by ConceptDestiny
hey folks,


Stuck on this bit of code, and its bugging the hell out of me. This page is designed to update the name of the "enclosure", however when updating the name, it doesn't seem to recognize '$enclosureid' in the where clause.

Code: Select all

<html>
    <?php

    include 'global.php';

    $enclosureid = $_GET['enclosureid'];    
    $enclosurename = $_GET['enclosurename'];

    if (isset($_POST['rename']))
    {
     $newenclosurename = addslashes(strip_tags($_POST['enclosurenameedit']));

         // UPDATE ENCLOSURE NAME
         $updateenclosure="UPDATE enclosure SET enclosurename='$newenclosurename' where enclosureid='$enclosureid'";
         mysql_query($updateenclosure) or die("Could not update enclosure name"); 
                    	echo "<center><br>Rename successful.";
                    	echo "<center><br><A href='javascript:history.go(-2)'>Go back";

    }
    else
    {

       $query = "SELECT * FROM enclosure WHERE enclosureid='$enclosureid'";
       $result = mysql_query($query) or die(mysql_error());
          $row = mysql_fetch_array($result) or die(mysql_error()); 
    $enclosureid = $_row['enclosureid']; 
          
    ?>
            <div id='site_container'>
            <form method="post" action="rename.php">
						<table border='0' align='center'>
							<tr>
								<td height='200' colspan='2'></div></td>
							</tr>
							<tr>
								<td colspan='2'><center>Rename<br><hr></center></td>
							</tr>
							<tr>
								<td align='right' width='50%'>Current enclosure name</td><td width='50%'><input type='text' name='enclosurenameedit' size='20' value='<?php echo "".$row['enclosurename'].""; ?>'></td>
							</tr>
							<tr>
							   <td><input type="hidden" name="Language" value="English"></td>
							</tr>
							<tr>
								<td colspan='2'><center><input type='submit' value='Rename' name='rename'><br /><br /><a href='javascript:history.go(-1)'>Back</a></center></td>
							</tr>
						</table>

	
                      </form>
            </div>

    <?php

    }

    ?>
<?php include 'footer.php'; ?>
</html>
Any help would be greatly appreciated! :)

Re: mysql field update question

Posted: Sat Nov 27, 2010 9:30 pm
by Jackolantern
Right above the SQL call, just do an

Code: Select all

 echo "Enclosure ID: ".$enclosureid;
(Be sure to add the text literal part in case it ends up being empty, or you won't even know it printed). Make sure the value is what you think it is.

Re: mysql field update question

Posted: Sat Nov 27, 2010 9:34 pm
by ConceptDestiny
Yeah, I've tried that. :(

The $enclosureid variable seems to get lost after the if (isset) statement.

Re: mysql field update question

Posted: Sat Nov 27, 2010 9:45 pm
by ConceptDestiny
I eventually figured that the $_POST function draws everything from the form, so I added a hidden input field with the enclosureid as the value. :D

Resolved code:

Code: Select all

<html>
    <?php

    include 'global.php';

    $enclosureid = $_GET['enclosureid'];    
     echo "Enclosure ID: ".$enclosureid."";
    if (isset($_POST['rename']))
    {
     $newenclosurename = addslashes(strip_tags($_POST['enclosurenameedit']));    
     $enclosureid = addslashes(strip_tags($_POST['enclosureid']));     

     
         // UPDATE ENCLOSURE NAME

         $updateenclosure="UPDATE enclosure SET enclosurename='$newenclosurename' where enclosureid='$enclosureid'";
         mysql_query($updateenclosure) or die("Could not update enclosure name"); 

         
                    	echo "<center><br>Rename successful. ".$descript3['enclosuredescription']."";
                    	echo "<center><br><A href='javascript:history.go(-2)'>Go back";
    }
    else
    {

       $query = "SELECT * FROM enclosure WHERE enclosureid='$enclosureid'";
       $result = mysql_query($query) or die(mysql_error());
          $row = mysql_fetch_array($result) or die(mysql_error()); 
 
          
    ?>
            <div id='site_container'>
            <form method="post" action="rename.php">
						<table border='0' align='center'>
							<tr>
								<td height='200' colspan='2'></div></td>
							</tr>
							<tr>
								<td colspan='2'><center>Rename<br><hr></center></td>
							</tr>
							<tr>
								<td align='right' width='50%'>Current enclosure name</td><td width='50%'><input type='text' name='enclosurenameedit' size='20' value='<?php echo "".$row['enclosurename'].""; ?>'></td>
							</tr>
							<tr>
							  <td><input type="hidden" name="enclosureid" value="<?php echo "".$row['enclosureid'].""; ?>"></td>
							</tr>
							<tr>
								<td colspan='2'><center><input type='submit' value='Rename' name='rename'><br /><br /><a href='javascript:history.go(-1)'>Back</a></center></td>
							</tr>
						</table>

	
                      </form>
            </div>

    <?php

    }

    ?>
<?php include 'footer.php'; ?>
</html>
Thanks for your help though, Jackolantern! :)

Re: $_POST form data question [Resolved]

Posted: Sun Nov 28, 2010 12:46 am
by Jackolantern
Ohhh, your form's action was "post"? If so, to have anything under $_GET, you must add them manually to the URL, so you would have to have something like this:

Code: Select all

 <form action="process.php?closureid=<?php echo $closureid; ?>" method="post">
...then complete your form as normal. That is the only way that you could have both $_GET and $_POST values at the same time. If your code was not set up that way, then no $_GET values were being sent through the URL.

Also, keep in mind that if you are using hidden form fields, that those can be altered by the player, so ensure that they are not something that could be used to exploit your game.

Re: $_POST form data question [Resolved]

Posted: Sun Nov 28, 2010 2:51 pm
by ConceptDestiny
Jackolantern wrote:Ohhh, your form's action was "post"? If so, to have anything under $_GET, you must add them manually to the URL, so you would have to have something like this:

Code: Select all

 <form action="process.php?closureid=<?php echo $closureid; ?>" method="post">
...then complete your form as normal. That is the only way that you could have both $_GET and $_POST values at the same time. If your code was not set up that way, then no $_GET values were being sent through the URL.

Also, keep in mind that if you are using hidden form fields, that those can be altered by the player, so ensure that they are not something that could be used to exploit your game.
Perfect, thanks for the info! :)