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

Link to comment
Share on other sites

Sorry, I try to be more clear !!  :)

 

I have a little db, a flat file, called 'iscritti.txt' and I just want to take informations FROM this flat file, with my php code,  and bring them into the html form...

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Right... I see this is another kind of problem... I will follow all explanations !!

 

Thanks so much for the correct code !!!!

 

 

I can use this forum to check if codes are right or not... if the forum is happy it gonna color them !! lol

Link to comment
Share on other sites

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.