Jump to content

[SOLVED] why isn't this working? POST displaying in URL as GET would...


tbare

Recommended Posts

alright, i don't know what's going on here, but whenever i click "edit" next to a quote, it works great. I see the quote in a textarea box with a submit button...

 

When i hit "Update" is when it all gets funny... as far as i can tell it's a php issue, and not a mysql issue, because the POST somehow changes to a GET (URI changes to "test.php?quote=

&id=[iD here]&update=Update")

 

wtf?

 

relavent code:

 

<?php
ob_start();
include_once('../commonFiles/wannaforkAdminConnect.php');
require_once('./functions/functions.php');


if(isset($_POST['update']))
{
$text = stripslashes(nl2br($_POST['quote'])); // Get text from form
$text = str_replace(array("\r\n", "\r", "\n"), "", $text);
$id = $_POST['id'];
echo $text."<br/>";
echo $id."<br/>";
$updateQuote = fEditRandomQuote($id,$text);
}


$randomQuotes = fGetAllRandomQuotes();
$randomQuoteCount = count($randomQuotes);



if(isset($_GET['action']) && $_GET['action'] == "edit" && isset($_GET['ID']))
{
$quote = fGetSingleRandomQuote($_GET['ID']);
$quoteID = $quote[0];
echo "Original quote: ".$quote[1];
echo "<form action=\"test.php\">";
echo "<textarea rows=\"5\" cols=\"65\" id=\"quote\" name=\"quote\">";
echo $quote[1];
echo "</textarea><br/>";
echo "<input type=\"hidden\" name=\"id\" id=\"id\" value=\"".$_GET['ID']."\" />";
echo "<input type=\"submit\" id=\"update\" name=\"update\" value=\"Update\"/>";
echo "</form>";
}
//This is just testing for now... ignore
elseif(isset($_GET['action']) && $_GET['action'] == "delete" && isset($_GET['ID']))
{
echo $_GET['ID'];
}

./
else
{
echo  "<table border=\"1\">\n";
for($i=0; $i < $randomQuoteCount; $i++)
	{
	echo "<tr><td>";
	echo $randomQuotes[$i][1];
	echo "</td><td><a href=\"".$_SERVER['PHP_SELF']."?action=edit&ID=".$randomQuotes[$i][0]."\">edit</a></td><td><a href=\"".$_SERVER['PHP_SELF']."?action=delete&ID=".$randomQuotes[$i][0]."\">delete</a></td></tr>\n";
	}
}

mysql_close($dbc);
ob_end_flush();
?>

 

and the functions in use:

<?php
function escapeData ($data)
{
global $dbc; //create the connection
if (ini_get('magic_quotes_gpc'))
	{
	$data = stripslashes($data);
	}
return mysql_real_escape_string ($data, $dbc);
} //end of escape_data function

if ( !function_exists('htmlspecialchars_decode') ) // make h.s.c._d. in PHP < v.4
{
   function htmlspecialchars_decode($text)
   {
       return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
   }
}

function fEditRandomQuote($id,$quote)
{
$query = "PREPARE EditRandomQuote0 FROM 'UPDATE RandomQuote SET Quote = ? WHERE ID = ?'"; $result = mysql_query($query) or die(mysql_error());
$query = "set @a = '" . escapedata($quote) . "'"; $result = mysql_query($query) or die(mysql_error());
$query = "set @b = '" . escapedata($id) . "'"; $result = mysql_query($query) or die(mysql_error());
$query = "EXECUTE EditRandomQuote0 USING @a,@b"; $result = mysql_query($query) or die(mysql_error());
$query = "DEALLOCATE PREPARE EditRandomQuote0"; $resultDeallocate = mysql_query($query) or die(mysql_error());
}

function fGetAllRandomQuotes()
{
$query = "PREPARE GetAllRandomQuotes0 FROM 'SELECT ID,Quote FROM RandomQuote ORDER BY ID'"; $result = mysql_query($query) or die(mysql_error());

// execute the prepared statement for Item Insert
$query = "EXECUTE GetAllRandomQuotes0"; $result = mysql_query($query) or die(mysql_error());

// deallocate the prepared statement for Item Insert
$query = "DEALLOCATE PREPARE GetAllRandomQuotes0"; $resultDeallocate = mysql_query($query) or die(mysql_error());
$i = 0;
     	while ($row = mysql_fetch_array ($result, MYSQL_BOTH))
     		{
     		$allRandomQuotes[$i][0] = $row['ID'];
     		$allRandomQuotes[$i][1] = $row['Quote'];
     		$i++;
	}

return $allRandomQuotes;
}

function  fGetSingleRandomQuote($ID)
	{
$query = "PREPARE GetRandomQuote0 FROM 'SELECT ID,Quote FROM RandomQuote WHERE ID LIKE ?'"; $result = mysql_query($query) or die(mysql_error());

$query = "set @a = '" . escapedata($ID) . "'"; $result = mysql_query($query) or die(mysql_error());

// execute the prepared statement for Item Insert
$query = "EXECUTE GetRandomQuote0 USING @a"; $result = mysql_query($query) or die(mysql_error());

// deallocate the prepared statement for Item Insert
$query = "DEALLOCATE PREPARE GetRandomQuote0"; $resultDeallocate = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array ($result, MYSQL_BOTH);
//     	print_r($row);
return $row;
}
?>

 

any ideas?

Pet peeve: I hate echoing HTML.  To me it just reads so much better if you close the php tag, lay out the html, and then <?php echo $x ?> if you want one variable inserted amongst it.  Personal preference though, it's certainly not what's stopping you.

 

Looks to me like this:

echo "<form action=\"test.php\">";
echo "<textarea rows=\"5\" cols=\"65\" id=\"quote\" name=\"quote\">";
echo $quote[1];
echo "</textarea><br/>";
echo "<input type=\"hidden\" name=\"id\" id=\"id\" value=\"".$_GET['ID']."\" />";
echo "<input type=\"submit\" id=\"update\" name=\"update\" value=\"Update\"/>";
echo "</form>";

Is the part where update requests get submitted.  And your form tag doesn't have a method, so it has been defaulting to get.

 

Try putting <form action="test.php" method="post"> and see if that works.

 

edit: too slow.  :P  Glad it's fixed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.