Yii Framework Forum: failed to access $_POST / $_GET - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

failed to access $_POST / $_GET Rate Topic: -----

#1 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 08 July 2010 - 02:11 PM

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 :

Posted Image

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

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 08 July 2010 - 02:16 PM

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

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

0

#3 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 08 July 2010 - 02:42 PM

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++;

?>


Posted Image
0

#4 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 10 July 2010 - 04:04 AM

up ?

When i use an double array ($data[$i] ($donnees_acquis[$nombre_elements_fait] in my script)) I get this error "undefinied offset :1
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 10 July 2010 - 04:21 AM

View PostCo-k-ine, on 08 July 2010 - 02:42 PM, said:

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


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

#6 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 10 July 2010 - 04:33 AM

<?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 ? ?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users