Jump to content

Problem with POST and GET


arghesis

Recommended Posts

This is really confusing for me.

 

I have tried to figure this out but just can't get it right ...

 

so, here i have a very simple example (yeah, I know, I have to pass to xhtml :) ) :

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Test page</TITLE>
</HEAD>
<BODY>
<?PHP
echo '<form action="'.$_SERVER['PHP_SELF'].'?page=somepage" method="post">
		<input type="text" name="text" value="Input text"/>
		<input type="submit" value="Submit!" name="submit"/>
		</form>';
if(isset($_POST['submit'])) {
	echo $_POST['text'];
	echo '<br/>The page you want to see is : ' . $_GET['page'];
}
?>

</BODY>
</HTML>

 

My site is like this : I have a template, and there I put my content in. I use GET in the menu, to go to the content of different pages. But the problem is that everywhere where I have a form, after I press Submit button, it takes me to index.php, instead of taking me to the place I tell it to go. Like $_SERVER['PHP_SELF']?page=whateverpage .

 

This is an example of a page: It's a simple mysql insert into a database. But when I click the Submit button, it takes me to index.php

 

povestiriProcess();

function arataPovestiri() {
$query = mysql_query('SELECT *FROM povestiri ORDER BY data DESC');
while($row = mysql_fetch_array($query)) {
	echo '<div class="povestiri"><div class="povestiri_nume">'.$row['nume'].'  ('.(filesize($row['nume'])/1024).' - <a href="'.$_SERVER['PHP_SELF'].'" target="_self">Download</a></div></div>';
}
}

function adaugaPovestireForm() {
echo '<br/><fieldset class="fieldset_adaugastire"><legend>Adauga Povestire</legend>';
echo '<form action="'.$_SERVER['PHP_SELF'].'?pg=povestiri" method="post" enctype="multipart/form-data">'.
'Nume:<br/><input type="text" name="nume" value=""/><br/>'.
'Continut:<br/><textarea name="continut"></textarea>'.
//'Adresa:<br/><input type="file" name="file" value=""/><br/>'.
'<input type="submit" name="adaugaPovestire" value="Adauga"/>'.
'</form></fieldset>';
}

function adaugaPovestire() {
if(isset($_POST['adaugaPovestire'])) {
	mysql_query('INSERT INTO povestiri(nume,link,data) VALUES("'.$_POST['nume'].'","'.$_POST['continut'].'",'.time().')');
}
}

function povestiriProcess() {
if(isLogged()) {
	if(isset($_POST['adauga'])) adaugaPovestire();
	if(isset($_GET['sterge'])) stergePovestire($_GET['sterge']);
}
arataPovestiri();
if(isLogged()) adaugaPovestireForm();
}

 

This is index.php

 

<?PHP
session_start();
require_once('php/mysql_connect.php');
require_once('php/functions.php');	
require_once('php/left_menu.php');
$_SESSION['logged']=1;
$_SESSION['user']='admin';
$_SESSION['suser']=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
	<?PHP include('php/header.php'); ?>
</head>
<body>
	<div id="wrapper"> 
		<div id="header">
			<div id="logo">  <!-- Admin pg - download header, change header - overwrite file header.jpg -->
				<img src="assets/header.jpg" alt="ImagoDei" width="700" height="150"/>
			</div>
   			<div id="topmenu">
			<ul> 			
				<li><a href="index.php">Home</a></li> 
				<li><a href="mailto:tobby_clx2005@yahoo.de">Trimite E-mail</a></li> 
				<li><a href="#">Biserica Speranta</a></li> 
			</ul> 
		</div> 
	</div>
	<div id="body"> 
		<div id="innerbody"> 
			<div id="leftcol">
				<div class="verticalmenu">
				<?PHP
				pageMenu();
				searchForm();
				?>
				</div>
			<?PHP
			login();
			if(isset($_POST['submitShoutbox'])) shout();
			shoutBox();
			if(isset($_SESSION['logged'])) {
				shoutBoxForm();
			}
			?>
			</div>
		</div>
   			<div id="centercol">
			<div id="centercontent">
				<?PHP
				if(isset($_GET['search'])=='yes') searchTerm($_POST['searchTerm']);
				else {
					if(!isset($_GET['pg'])) $_GET['pg']='home';
					if(is_file($_GET['pg'].'/'.$_GET['pg'].'.php')) require_once($_GET['pg'].'/'.$_GET['pg'].'.php');
					else echo 'Pagina inexistenta!';
				}
				?>
			</div>
		</div>
	</div>	
	<div id="rightcol">
		<?PHP
		links();
		?>
	</div> 
	<div class="clear"></div> 
	</div>
	</div>
	<div id="footer"><?PHP include('php/footer.php'); ?></div>
</body>
</html>

 

EDITED BY WILDTEEN88: Please use code tags (


) when posting code. Thank you. I have modified you post to include code tags

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.