$_POST form data question [Resolved]

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
ConceptDestiny
Posts: 261
Joined: Wed Apr 28, 2010 8:35 am

$_POST form data question [Resolved]

Post 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! :)
Last edited by ConceptDestiny on Sat Nov 27, 2010 9:47 pm, edited 2 times in total.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: mysql field update question

Post 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.
The indelible lord of tl;dr
ConceptDestiny
Posts: 261
Joined: Wed Apr 28, 2010 8:35 am

Re: mysql field update question

Post by ConceptDestiny »

Yeah, I've tried that. :(

The $enclosureid variable seems to get lost after the if (isset) statement.
ConceptDestiny
Posts: 261
Joined: Wed Apr 28, 2010 8:35 am

Re: mysql field update question

Post 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! :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: $_POST form data question [Resolved]

Post 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.
The indelible lord of tl;dr
ConceptDestiny
Posts: 261
Joined: Wed Apr 28, 2010 8:35 am

Re: $_POST form data question [Resolved]

Post 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! :)
Post Reply

Return to “Advanced Help and Support”