failed to access $_POST / $_GET

Hi : )

I have difficulties to access to my global $_GET and $_POST from my code.

If i understand it right, a simple " if ($_GET[‘request’]== ‘search’) " must work, but its not working and i dont know where/how i can fix it.

my script :




<?php


if ( empty($_POST) )

{

// Formulaire de recherche

?>

Entrer le nom du manga recherché :<br /><br />

<form action="index.php?r=animes/create" method="post">

<input type="text" name="titre"><input type="submit" value="Rechercher">

<input type="hidden" name="token" value ="abcdef">

</form>

<br /><br />

<?php

}


// Début du script de parsing Animeka

if($_GET['animeka'] == 'search')

{	

$titre =$_POST['titre'];

$url_search = "http://www.animeka.com/search/index.html?req=anime%3A+$titre";

	$page = file_get_contents($url_search);

}



I am also this error screen :

Can you please help me and tell me where i am wrong.

It’s a good practice to check if an array key exists before use it:




if (!empty($_GET['animeka']) && $_GET['animeka'] == 'search') ...



Hi

Thanks for your answer, now its working well.

I have another error, but without using Wii its working.

my script :





<?php

$donnees_acquis = str_replace('</a>', '', $donnees_acquis);

			$donnees_acquis = str_replace('<br>', '', $donnees_acquis);

			$donnees_acquis = str_replace('<br />', '', $donnees_acquis);

			$url_acquis = preg_replace('#<a href="/animes/detail/(.+)">#', '<input type="radio" name="url" value="$1" />', $donnees_acquis[$nombre_elements_fait]);

			

			

			// On affiche chaque élément

			echo $url_acquis;

			echo '<br />';

			$nombre_elements_fait++;


?>

up ?

When i use an double array ([color="#0000FF"]$data[/color][color="#FF0000"][$i][/color] ([color="#0000FF"]$donnees_acquis[/color][color="#FF0000"][$nombre_elements_fait][/color] in my script)) I get this error "undefinied offset :1

That’s o.k., because you should not use your Wii while you’re working … :D

Seriously, you try to access some array element with $donnees_acquis[$nombre_elements_fait]) that does not exist. We have no idea where you create that array in your code and what $nombre_elements_fait contains. So it’s up to you to fix these code parts. This has nothing to do with Yii but is basic PHP…


<?php


if (!empty($_GET['animeka']) && $_GET['animeka'] == 'search')

{	

	$titre = htmlspecialchars($_POST['titre']);

	$url_search = "http://www.animeka.com/search/index.html?req=anime%3A+$titre";

	$page = file_get_contents($url_search);

		

	

		$donnees_acquis = recherche($page, 'résultats) :</b><br><br>• ', '<br></td></tr></table></center></td></tr></table>');

		

		// On capture le nombre de résultats trouvé

		$nombre_elements = recherche($page, '</B></I> ( ', ' résultats ) :</td>');

		

	

		[...]

		// On coupe les informations recueillis

		$donnees_acquis = explode('•',$donnees_acquis);

		

		// On affiche les informations receuillis (précédement coupés)

		$nombre_elements_fait = 0;

		

		// On démarre le formulaire de sélection

		?><form action="?animeka=true" method="post"><?php

	

		while ($nombre_elements_fait < $nombre_elements)

		{

			[...]

			$url_acquis = preg_replace('#<a href="/animes/detail/(.+)">#', '<input type="radio" name="url" value="$1" />', $donnees_acquis[$nombre_elements_fait]);

			

			

			$nombre_elements_fait++;

		}

		

		// On referme le formulaire

		?><br /><input type="submit" value="Valider"></form><?php

	

}

And my function : recherche


<?php

function recherche($texte, $debut, $fin)

{

	$phrase_recherchee = strstr($texte, $debut);

	

	if($fin != "")

	{

		$phrase_recherchee = explode($fin, $phrase_recherchee);

		$phrase_recherchee = str_replace($debut,'',$phrase_recherchee[0]);

	}

	

	$phrase_recherchee = trim($phrase_recherchee);


	return $phrase_recherchee;

}

?>

do $donnees_acquis must be undefinied, isnt it ? ?