arghesis Posted July 10, 2007 Share Posted July 10, 2007 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:[email protected]">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 https://forums.phpfreaks.com/topic/59237-problem-with-post-and-get/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.