arghesis Posted June 20, 2007 Share Posted June 20, 2007 Hy there, I have this in my index.php file. I have a menu with $_GET <?PHP $err='<h3>Error Page!</h3>'; if(isset($_GET['search'])=='yes') searchTerm($_POST['searchTerm']); else { if(!isset($_GET['pg'])) $_GET['pg']='home'; if(is_file($_GET['pg'].'.php')) require_once($_GET['pg'].'.php'); else echo 'No such file'; } ?> Then i have another file called video.php function arataVideoclip() { $query = mysql_query('SELECT * FROM videoclipuri ORDER BY id'); while ($row = mysql_fetch_array($query)) { echo '<b>'.$row['nume'].'</b>'; if(isLogged() && isset($_SESSION['suser'])==1) echo ' - <a href="'.$_SERVER['PHP_SELF'].'?pg=videoclipuri&sterge='.$row['id'].'" target="_self">Delete</a>'; echo '<br/>'.$row['adresa']; echo '<br/>'; } if(isLogged()) adaugaVideoclipForm(); } function stergeVideoclip($id) { mysql_query('DELETE FROM videoclipuri WHERE id='.$id); } function adaugaVideoclipForm() { echo '<br/><fieldset class="fieldset_adaugastire"><legend>Adauga Videoclip</legend>'; //Here is my problem. When I press the submit button, it takes me to the index.php file, instead of processing the data in the form //It is really weird and I can't find the solution to it. Please help me. echo '<form action="'.$_SERVER['PHP_SELF'].'?pg='.$_GET['pg'].'" method="post">'. 'Nume:<br/><input type="text" name="nume" value=""/><br/>'. 'Adresa:<br/><input type="text" name="adresa" value=""/><br/>'. '<input type="submit" name="adaugaVideo" value="Adauga"/>'. '</form></fieldset>'; } function adaugaVideoclip() { $nume = $_POST['nume']; $adresa = $_POST['adresa']; mysql_query('INSERT INTO videoclipuri(nume,adresa) VALUES("'.$nume.'","'.$adresa.'")'); } function videoclipuriProcess() { if(isLogged()) { if(isset($_POST['adaugaVideo'])) adaugaVideoclip(); else if(isset($_SESSION['suser'])==1 && isset($_GET['sterge'])) stergeVideoclip($_GET['sterge']); } arataVideoclip(); } videoclipuriProcess(); What I'm doing is make a template page: index.php and then just require_once('file.php') in the content area of the template page. So every page that i include, only has the functions in them. I use GET to navigate trough the menu. When I enter the video.php page, I have several functions for displaying database entries, option for deleting them, etc ... and I have an add Form if you are logged in. This is where the problem occurs. I'm thinking that it goes back to index.php, to the if condition and enters the first one (that it doesn't have any GET parameter). So it shows the first page sett up. But, since i have $_SERVER['PHP_SELF'].'?pg=videoclipuri' it should also send the GET parameter with it. Any advice ? Quote Link to comment https://forums.phpfreaks.com/topic/56348-_serverphp_self-problem-cant-understand-it-pls-help/ Share on other sites More sharing options...
AndyB Posted June 20, 2007 Share Posted June 20, 2007 Since the red form method is post, there are no 'get' variables to be found, Quote Link to comment https://forums.phpfreaks.com/topic/56348-_serverphp_self-problem-cant-understand-it-pls-help/#findComment-278382 Share on other sites More sharing options...
arghesis Posted June 20, 2007 Author Share Posted June 20, 2007 Can I use then a hidden input type ? Is it safe ? Could you please tell me a bit about using hidden input types ? Or point me to some good reading if you know any ? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/56348-_serverphp_self-problem-cant-understand-it-pls-help/#findComment-278458 Share on other sites More sharing options...
AndyB Posted June 20, 2007 Share Posted June 20, 2007 Yes you could use a hidden variable ... but why not just change the form method to "get"? Quote Link to comment https://forums.phpfreaks.com/topic/56348-_serverphp_self-problem-cant-understand-it-pls-help/#findComment-278837 Share on other sites More sharing options...
arghesis Posted June 21, 2007 Author Share Posted June 21, 2007 I have tryed using method="get". Also I have tryed with hidden input. It does the same. This is extremly weird. It didn't even cross my mind that $_SERVER['PHP_SELF']?page=somepage doesn't works because i used it before on other pages. With method="post". It just simply doesn't pass my get variables ... It should work, since I add the get variable ... even if it has method="post" ... That passes the variables from the form in the $_POST array(), but the action (the 'page direction') should be $_SERVER['PHP_SELF']?page=somepage I'll try doing a test page and see how it works there .... with a form and everything ... Quote Link to comment https://forums.phpfreaks.com/topic/56348-_serverphp_self-problem-cant-understand-it-pls-help/#findComment-279486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.