Jump to content

$_SERVER['PHP_SELF'] Problem ... can't understand it ... Pls help


Recommended Posts

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 ?

 

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

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.