"Writing to file" trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neil692006
Forum Newbie
Posts: 1
Joined: Wed Apr 05, 2006 3:49 am

"Writing to file" trouble

Post by neil692006 »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


help....i have trouble debugging this code for my guestbook 
it was working before but now there's something wrong.  it cannot 'write to file'

filename - viewguestbook.php

Code: Select all

<html>
<head><title>view guest book</title>
</head>
<body bgcolor=lightblue>
<center>
<font size=5 color=darkblue><b>View Guestbook</b></font><br>
<a href="addguest.php">Sign In Guestbook</a><br><br>

<table border=0 width=309 bgcolor=yellow>
<?php
if($action=="add"){

$name=$_POST["name"];
$loc=$_POST["loc"];
$email=$_POST["email"];
$gender=$_POST["gender"];
$msg=$_POST["msg"];

$content=$name.",".$loc.",".$email.",".$gender.",".$msg."\n";

}

else{
echo "<META HTTP-EQUI=\"refresh\"
content=\"2; URL=guestbook.php\">";
}

$handle=fopen("text.txt", "r");
 while($data=fgetcsv($handle,1000,",")){
      $num=count($data);
      for($c=0; $c<$num; $c++){
       switch($c){
       case 0: echo "<tr> <td width=28% bgcolor=#D5E2FF>
               Name: &nbsp &nbsp &nbsp; </td>
                          <td width=72% bgcolor=#D5E2FF>$data[$c] </td>
                     </tr>"; break;

       case 1: echo "<tr> <td width=28% bgcolor=#C6D7FF>
               Location: &nbsp &nbsp &nbsp; </td>
                          <td width=78% bgcolor=##C6D7FF>$data[$c] </td>
                     </tr>"; break;

       case 2: echo "<tr> <td width=28% bgcolor=#D5E2FF>
               Email: &nbsp &nbsp &nbsp; </td>
                          <td width=72% bgcolor=#D5E2FF>$data[$c] </td>
                     </tr>"; break;

       case 3: echo "<tr> <td width=28% bgcolor=#C6D7FF>
               Gender: &nbsp &nbsp &nbsp; </td>
                          <td width=78% bgcolor=##C6D7FF>$data[$c] </td>
                     </tr>"; break;

       case 4: echo "<tr> <td width=28% bgcolor=#D5E2FF>
               Message: &nbsp &nbsp &nbsp; </td>
                          <td width=72% bgcolor=#D5E2FF>$data[$c] </td>
                     </tr>
                     <tr><td>&nbsp;</td><td>&nbsp;</td></tr>"; break ;

       }}
 // echo "<br>".$namex."<br>".$locx."<br>".$emailx."<br>".$genderx."<br>".$msgx."<br>";
   }
 fclose($handle);
 ?>
</table>
</center>  
</body>
</html>
addguest.php

Code: Select all

<html>
<head><title>addguest</title>
</head>
<body>
<form name="form" action="viewguestbook.php?action=add" method="POST">

Name: &nbsp &nbsp &nbsp       <input type="text" name="name" size="40" maxlenght="20"><br>
Location: &nbsp               <input type="text" name="loc" size="40" maxlenght="20"><br>
Email: &nbsp &nbsp &nbsp&nbsp <input type="text" name="email" size="40" maxlenght="20"><br>
Gender: &nbsp&nbsp&nbsp       <input type="text" name="gender" size="40" maxlenght="20"><br>
Message: &nbsp                <textarea name="msg" col=5 row=10> </textarea> <br><br><br>
<input type="submit" name="content" value="SUBMIT">

</form>
</body>
</html>

text.txt

Code: Select all

Gerry Parco,Quezon City,gparco@yahoo.com,male,galing galing,
Rico Palmes,lapaz,rpalmes@upv.edu,male,great!

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I don't see where you're writing to the file with fwrite() ?

And if you are and I missed it, check that the files permissions allow information to be written to it. CHMOD 0777 is the easy fix.

Also, your code assumes register_globals is on, it may be off.

Lastly, use PHP and CODE tags when posting your code.. it makes it easier to read. :)

Hope that helped.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply