Jump to content

[SOLVED] Get variables into a form


PhpRay

Recommended Posts

Hi !!

 

I don't understand why this codes don't work... ( They are in the same directory...) the problem is that in the fields of the form appear the variable but in the literally way: <?=$cid?>

 

HTML code:

 

<html>
      <form method="post" action="http://localhost/open.php">
ID: <input type="text" size="10" name="id" value="<?=$cid?>"><br>	
NOME: <input type="text" size="10" name="nome" value="<?=$cnome?>"><br>
COGNOME: <input type="text" size="10" name="cognome" value="<?=$ccognome?>"><br>
EMAIL: <input type="text" size="10" name="email" value="<?=$cemail?>"><br>
<input type="submit" value="Modifica"><br>
      </form>	     





</html>


PHP code:

<?php

$textfile = fopen("iscritti.txt", "r");



while ($rigafile = fgets($textfile, 1024)){

$camporiga = explode("|", $rigafile);
$idriga = $camporiga[0];

if($idriga == 3){
 $cid = $camporiga[0];
 $cnome = $camporiga[1];
 $ccognome = $camporiga[2];
 $cemail = $camporiga[4];
}
}

fclose($textfile);

?>

 

Where's the problem please? I chenged many times the url yet just to try !!

 

 

Link to comment
https://forums.phpfreaks.com/topic/159047-solved-get-variables-into-a-form/
Share on other sites

If I am interpreting your English correctly, you are giving the variables these values and the user submission isn't going through.  I did not see the you gather the "posted" variables.  Try the $variable = $_POST['name'] method and see if it passes the user input.

does the file you have your php in look like this all in one file... with file name ending in ".php"


<?php

$textfile = fopen("iscritti.txt", "r");



while ($rigafile = fgets($textfile, 1024)){

$camporiga = explode("|", $rigafile);
$idriga = $camporiga[0];

if($idriga == 3){
 $cid = $camporiga[0];
 $cnome = $camporiga[1];
 $ccognome = $camporiga[2];
 $cemail = $camporiga[4];
}
}

fclose($textfile);

?>

<html>
      <form method="post" action="http://localhost/open.php">
ID: <input type="text" size="10" name="id" value="<?=$cid?>"><br>	
NOME: <input type="text" size="10" name="nome" value="<?=$cnome?>"><br>
COGNOME: <input type="text" size="10" name="cognome" value="<?=$ccognome?>"><br>
EMAIL: <input type="text" size="10" name="email" value="<?=$cemail?>"><br>
<input type="submit" value="Modifica"><br>
      </form>	     
</html>

 

 

also try looking into functions like, file() or file_get_contents() it might make life a bit easier... :-)

 

http://us.php.net/manual/en/function.file.php

http://us.php.net/manual/en/function.file-get-contents.php

The code is not ok, your using short tags. Dont.

 

eg; This....

 

EMAIL: <input type="text" size="10" name="email" value="<?=$cemail?>"><br>

 

should be....

 

EMAIL: <input type="text" size="10" name="email" value="<?php echo $cemail; ?>"><br>

 

See? Even our forum software likes it better.

 

Besides, easyphp and xampp are not different pieces of software, just different configurations.

Thanks.. but it doesn't work.. so how can I change configuration ? I tried to click with right btn of mouse and I found the voice 'configuration' but I wasn't able to change anything there...

 

Take a look at the php.ini file. This way you'll be able to configure php within any environment not just some quick easy install.

 

Now, define doesn't work. Obviously you have an install issue. You should post in the appropriate board.

Archived

This topic is now archived and is closed to further replies.

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