here is my function.when i click on the readp button,it will show undefined variable,but still can show out the string in txt file.

<?php
if(isset($_GET['readp'])){
readinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp);
}
?>

<?php
function readinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp){
$info=file('log.txt');
for($i=count($info)-1;$i>=0;--$i){
echo cleanOutputData($info[$i])."<br>";
}
}
?>

Recommended Answers

All 8 Replies

Where are you setting your $fname, $lname, $phone etc... variables?

$info= fopen("log.txt", "a+");
        $newinfo=$fname . "---". $mname . "---".$lname . "---".$gender. "---".$city. "---".$country."---". $phone . "---".$fax."---". $email."---"."$exp" ."\r\n";
        fwrite($info,$newinfo);
        fclose($info);
        }

here is my code

That's where you're outputting it, somewhere in your code you need to set those variables i.e.

$fname = "This is may name";
etc

here is my full code

<html>
<head><link rel="stylesheet" href="b.css"></head>
</body>
<form action="mid.php" method="get">
<h1><p class='head'>CUSTOMER REGISTRATION FORM</p></h1>
<input type="submit" name="readp" value="Read Profile"></br>
<h2><p class='head'>Biolographical Information</p></h2></br>
<table>
<tr>
<td>First Name:</td>
<td><input type="textbox" name="fname">*</td>
</tr>
<tr>
<td>Middle Name:</td>
<td><input type="textbox" name="mname"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="textbox" name="lname">*</td>
</tr>
<tr>
<td>Gender:</td>
<td>
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</td>
</tr>
<tr>
<td>City:</td>
<td><input type="textbox" name="city"></td>
</tr>
<tr>
<td>Country:</td>
<td><input type="textbox" name="country"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="textbox" name="phone">*</td>
</tr>
<tr>
<td>Fax:</td>
<td><input type="textbox" name="fax"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="textbox" name="email">*</td>
</tr>
<td>Experience:</td>
<td>
<select name="exp">
<option value="Beginner">Beginner</option>
<option value="Moderate">Moderate</option>
<option value="Expert">Expert</option>
</select>
</td>
<tr>
<td></td>
<td><input type="submit" name="signup" value="Sign Up"></td>
</tr>
</table>
<?php
if(isset($_GET['signup'])){
$fname=$_GET["fname"];
$lname=$_GET["lname"];
$phone=$_GET["phone"];
$email=$_GET["email"];
$mname=$_GET["mname"];
$gender=$_GET["gender"];
$city=$_GET["city"];
$country=$_GET["country"];
$fax=$_GET["fax"];
$exp=$_GET["exp"];
vinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp);
}
if(isset($_GET['readp'])){
readinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp);
}
?>
</form>
</body>
</html>


<?php
function vinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp){
if(empty($fname) || empty($lname) || empty($phone) || empty($email)){
echo "Please enter all the information";
}else{
if(is_numeric($phone)==false){
echo "Please enter the numbers only for phone";
}else{
if(strpos($email,'@')==false){
echo "Missing @ in your email, please enter the correct format";
}else{
$info= fopen("log.txt", "a+");
        $newinfo=$fname . "---". $mname . "---".$lname . "---".$gender. "---".$city. "---".$country."---". $phone . "---".$fax."---". $email."---"."$exp" ."\r\n";
        fwrite($info,$newinfo);
        fclose($info);
        //readinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp);
}
}
}
}
?>
<?php
function readinfo($fname,$lname,$phone,$email,$mname,$gender,$city,$country,$fax,$exp){
$info=file('log.txt');
for($i=count($info)-1;$i>=0;--$i){
echo cleanOutputData($info[$i])."<br>";
}
}
?>
<?php
function cleanOutputData($str){
$str=stripslashes($str);
return $str;
}
?>

When you call the readinfo function, all you want to do is output the contents of the file is that correct?

Than there is no need to include the variables, they're not used for reading the file:

if(isset($_GET['readp'])){
readinfo();
}

And

function readinfo(){
$info=file('log.txt');
for($i=count($info)-1;$i>=0;--$i){
echo cleanOutputData($info[$i])."<br>";
}
}

thank you very much.solve my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.