473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fwrite error

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // The data file where messages are stored.
  3. include ('messages.txt');
  4.  
  5. $dataf = "messages.txt";
  6.  
  7. // Max length of of messages
  8. $length = 150;
  9.  
  10. // Number of messages shown.
  11. $comments = 50;
  12.  
  13. $textsize = 4;
  14.  
  15. if (!$name)
  16. { $name = "||"; }
  17.  
  18. else $name .= ":";
  19.  
  20. $message = stripslashes($message);
  21.  
  22. $wrap = intval((20)/($textsize-2))+1;
  23.  
  24. $message = wordwrap($message, $wrap, ' ', 1);
  25.  
  26. $comfile = file($dataf);
  27.  
  28. if ($message != "") 
  29. {    
  30.  
  31. $df = fopen($dataf, "w");
  32.  
  33. fwrite ($df,"<a href="mailto:$email">@</a>
  34. <a href="$url" target="_blank">
  35. <b> $name</b>
  36. </a>
  37. $messagen<br>");
  38. }
  39. for ($i = 0; $i < $comments; $i++) 
  40. {
  41. fwrite ($df, $comfile[$i]);
  42. }
  43. fclose($df);}
  44. Header("Location: $HTTP_REFERER");
  45.  
  46. ?>
  47. <body>
  48.  <form method="POST" action="shout.php">
  49. <table width="100%">
  50. <tr>
  51. <td>Name:</td>
  52. <td><input size="17" maxlength=18 type="text" name="name"></td>
  53. </tr>
  54. <tr>
  55. <td>URL:</td>
  56. <td><input size="17" maxlength="35" type="text" name="url" value="http://"></td>
  57. </tr>
  58. <tr>
  59. <td>Email:</td>
  60. <td>
  61. <input size="17" maxlength="35" type="text" name="email" value="your@mail.com">
  62. </td>
  63. </tr>
  64. <tr>
  65. <td>Message:</td>
  66. <td><input size="17" maxlength="150" type="text" name="message"></td>
  67. </tr>
  68. <tr>
  69. <td colspan="2">
  70. <center>
  71. <input type="submit" value="Shout">
  72. <input type="reset" value="Clear">
  73. </td></tr></table> 
  74. </body>
hi im a begineer in php ....this is the form im testing.........its shows the error
Parse error: syntax error, unexpected T_STRING..........can anybody help me...
Nov 13 '08 #1
3 2699
Markus
6,050 Expert 4TB
Hey there, anandhmca05, and welcome to the forums. For the sake of our experts, we ask that you wrap [code] tags around any code you post, as it makes reading the code a lot easier and in turn increases the chance of a solution to your problem. If you are unsure how to do this, highlight the code and then hit the '#' button at the top of the text editor, or you can read the Posting Guidelines to become familiar with and stay within the posting guidelines.

Enjoy your stay,
Moderator.

ps. Using one period (full stop) is quite enough. Using many of them makes a post hard to read/understand.
Nov 13 '08 #2
Dormilich
8,658 Expert Mod 8TB
you forgot to escape the quotation marks in your string, thus getting a syntax violation. more on php.net's string reference.

regards
Nov 13 '08 #3
Markus
6,050 Expert 4TB
When you get an error/warning from PHP you are usually given a line number. For people such as my self, having the line number takes away the need to trawl the code and manually find the error, ergo, wasting time.

Anyway, I decided to have a look as I'm not racked for time. The error occurs on line 33. You use double quotes inside double quotes, therefore, terminating the string before you want, causing an error. You either need to escape the double quotes or change the double quotes to single quotes.

Consider the below:
Expand|Select|Wrap|Line Numbers
  1. $string = "Mark says, "Hello""; // this will cause an error
  2. $string = "Mark says, \"Hello\""; // this will work (notice the backslash, that escapes characters.
  3. $string = "Mark says, 'Hello'"; // will work (notice the single quotes)
  4. $string = 'Mark says, "Hello"'; // will work (notice single and double quotes were swapped)
  5.  
Hope this helps.
Markus.

Edit: darn it, domilich! You got there just before me.
Nov 13 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tuuska | last post by:
Hello! I have this problem, when fwrite() writes to the beginning of xyz.txt file, it overwrites the first line. Any ideas how to prevent this? I'm running PHP 4.3.3RC3 on Linux. <?php $fp =...
8
by: Brady | last post by:
Hi, I'm having a problem reading and writing to a file. What I'm trying to do is read a file, modify the portion of the file that I just read, and then write the modified data back to the same...
17
by: SW1 | last post by:
I wrote a small program which does something like tftp - transfering files and some chat, anyway i got a problem with fwrite, here is a snippet of my code: while(length > 0) { putchar('.');...
15
by: Suraj Kurapati | last post by:
Hello, I'm having a rather strange bug with this code: for certain values of 'buf', a segmentation fault occurs when 'free(buf)' is followed by an 'fwrite()'. In the program output, there is no...
10
by: cs | last post by:
if i have typedef struct{ unsigned a; unsigned *b; }tp; i would like to ask if it is ok for the "C standard 89" doing something like this {
4
by: ibrahimover | last post by:
typedef struct{ char name; int no; }TAM; typedef struct{ char name; char ch; }HARF;
10
by: Sheldon | last post by:
Hi, I am trying to learn C from scratch and, though I do know how to program in Python, many things in C are hard to understand - even after reading the examples. I guess because so many...
11
by: David Mathog | last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix write, but no fwrite. That is, no portable C method for writing binary data, only system calls which were OS specific. At...
2
by: miraan | last post by:
Hi, I am trying to create a script that creates other php scripts but I am getting a problem, when I create the file and use fwrite() to write to it, it returns an error saying: Parse error: syntax...
12
by: arnuld | last post by:
WANTED: Even if I do Ctrl-C in the middle of fgets(), fwrite() should write the previously entered data to a file (except if I hit the file-size limit) PROBLEM: If I do a Ctrl-C in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.