Page 1 of 1

help with returning values from form action

Posted: Mon Feb 13, 2006 11:52 am
by drew12
HI!

I have a webpage with a textfield for a username, a subit button and a textfield to display results. I'm am trying to check if a text file exists first with the username the user enters. So if they enter a username joe then i need to check if joe.txt exists in my root dir. Using Apache 2.0. If it does exist i need to return, to the page, "doesnt exist" in the second textfield. I am also trying NOT to naviagte away from the webpage, if not navigate to xxxcom/Fexists.php?

any help would be great!


Html code i'm using is,

Code: Select all

<form method="POST" action="Fexists.php">
<p><input type="text" name="SFile" size="20" value="Your filename here">
<input type="submit" value="Submit" name="B1"></p>
</form>
Fexists.php.

Code: Select all

<?php 

   $Zref = $_REQUEST['SFile']; 
   $Zref =  $Zref.".txt"; 
       
   if (file_exists("files/".$Zref)) { 
   
   echo "File exists try another"; 

   } 

   else { 

   echo "File doesn't exists"; 
    
   } 

?>

Posted: Mon Feb 13, 2006 12:32 pm
by Chris Corbyn

Code: Select all

<?php

$value = '';
if (isset($_POST['username']))
{
    if (!file_exists($_POST['username'].'.txt'))
        $value = 'File doesn\'t exist';
    else
        $value = 'File exists, try another';
}

?>
<form action="this_script.php" method="post">
Username: <input type="text" name="username" /><br />
File: <input type="text" name="file" value="<?= $value ?>" /><br />
<input type="submit" name="submit" value="Submit" />
</form>