PHP Help plz!! Small Error!

Ranhiru

Member
Feb 2, 2007
6,438
42
0
Inside FIREFOX
I dunno it was working fine...and i did not change anything actually but suddenly this error keeps on coming... i dont know why!! please help!! :) Im trying to such a simple thing! Display what was sent by a form! datz all!!

Code:
<?php 

    $name = $_POST["txt_name"];
    
    
?>

<html>

<head>  

<title> Guest Boook</title>

</head>

<body>

 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
 
  <center>
 Name : <input type="text" name="txt_name"> </input>    
 Email : <input type="text" name="txt_email"> </input>
 <br>
 <br>

 Comment
 <br>
 
 <textarea name="txt_comment" style="width : 75%" rows=10" ></textarea>
 

 
 <br>
 <br>
 <input type="submit" value="Submit"> </input>
 
 
 </center>
 
  
 
 
 </form>
 
 
 


</body>



</html>


But when i try to run this in Wamp Server v2.0

i get the following error!

Notice: Undefined index: txt_name in C:\WAMP\www\GuestBook.php on line 6

Please HELP!!! :(
 

sri_lion

Member
Sep 14, 2006
12,908
102
0
Kuala Lumpur
I tried nothing wrong, just that you haven't *printed* it on screen! :)

Code:
<?php 

    $name = $_POST["txt_name"];
	$email = $_POST["txt_email"];
	$comment = $_POST["txt_comment"];
	echo $name;
	echo "<br>";
	echo $email;
	echo "<br>";
	echo $comment;
	echo "<br>";
?>

<html>
<head>  
<title> Guest Boook</title>
</head>
<body>
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
 <center>
 Name : <input type="text" name="txt_name"> </input>    
 Email : <input type="text" name="txt_email"> </input>
 <br>
 <br>
 Comment
 <br>
 <textarea name="txt_comment" style="width : 75%" rows=10" ></textarea>
 <br>
 <br>
 <input type="submit" value="Submit"> </input>
 </center>
 </form>
</body>
</html>
 

kosandpol

Well-known member
  • Jun 10, 2008
    45,329
    1,492
    113
    Ranhiru said:
    So u think Wamp is the culprit??? :(
    most probably. Some other setting you've changed on php config must be getting in the way. Especially since it says something about "index"
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    sri_lion said:
    I tried nothing wrong, just that you haven't *printed* it on screen! :)


    But when i try to run i get these errors!!



    Notice: Undefined index: txt_name in C:\WAMP\www\Guest.php on line 3

    Notice: Undefined index: txt_email in C:\WAMP\www\Guest.php on line 4

    Notice: Undefined index: txt_comment in C:\WAMP\www\Guest.php on line 5


    what im furious is that this was working just fine!! no errors!! but suddenly this happend!
     

    sri_lion

    Member
    Sep 14, 2006
    12,908
    102
    0
    Kuala Lumpur
    Ok, create a new folder inside the root, copy paste this file only and name it as "index.php" and try to run from there!

    If possible restart Apache before that!
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    kosandpol said:
    another thought, what test data did you enter as name to check this script ?


    ohhh :D :D :D
    the problem comes when i run the script :D
    But when i actually input data and Submit they are nicely replaced... so what i should do is actually check whether variable actually contains data :D

    what the best way to do it???
    will strlen work??
     

    sri_lion

    Member
    Sep 14, 2006
    12,908
    102
    0
    Kuala Lumpur
    Here's on my localhost it works, I'm using XAMPP though!

    phpexample.JPG
     

    kosandpol

    Well-known member
  • Jun 10, 2008
    45,329
    1,492
    113
    Ranhiru said:
    ohhh :D :D :D
    the problem comes when i run the script :D
    But when i actually input data and Submit they are nicely replaced... so what i should do is actually check whether variable actually contains data :D

    what the best way to do it???
    will strlen work??
    It should. A sanity check to see if the variable has any data before assigning is pretty much a standard in good programming.
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Yeah as i see when the first time i run the page the error comes... but when i press the submit button WITHOUT any data ,the errors disappear... and with data it works, like it should work :)
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Code:
    <?php 
    [COLOR=Red]
        $name = $_POST["txt_name"];
        $email = $_POST["txt_email"];
        $comment = $_POST["txt_comment"];[/COLOR]
        
        if (strlen($name) > 0)
        echo $name;
        
        echo "<br>";
        
        if (strlen($email) > 0)
        echo $email;
        
            
        echo "<br>";
        
        if (strlen($comment) > 0)
        echo $comment;
        
        
    ?>


    i did a check but still the errors are pointing as soon as i run the page...and they are pointing @ the lines in red... and as soon i do a submit the page runs fine...without any error!
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Code:
        @$name = $_POST["txt_name"];
        @$email = $_POST["txt_email"];
        @$comment = $_POST["txt_comment"];


    i hid the error messages so its not outputting the errors.... but hithata madi wage :( :(
    because i dunno what causes the error in my machine! :(
     

    sri_lion

    Member
    Sep 14, 2006
    12,908
    102
    0
    Kuala Lumpur
    Ranhiru said:
    i did a check but still the errors are pointing as soon as i run the page...and they are pointing @ the lines in red... and as soon i do a submit the page runs fine...without any error!

    Have you tried what I suggested earlier copying the file into a new directory?
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    sri_lion said:
    Have you tried what I suggested earlier copying the file into a new directory?


    Nope :( The error remains

    But adding a @ before the coding suppresses the output of errors.. so the code LOOKS like it is working fine...