Help with coding!

sableye

She's Mine!
  • 210
    Posts
    21
    Years
    • Age 33
    • Seen Sep 13, 2005
    i cannot see the problem with this code but it keeps coming up with the error
    Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/pichunet/public_html/ichigokenkyuujo/Blog/added.php on line 32
    Please help here is the code:
    Code:
    <?php 
    $filename = "news.php";
    $file = fopen( $filename, "w");
    $sring = "<center>
    <table>
    <tr>
    <td>
    Posted on: $date Title: $title 
    </td>
    </tr>
    <tr>
    <td>
    $news
    </td>
    </tr>
    <tr>
    <td>
    Currently listening to: $listen 
    </td>
    </tr>
    <tr>
    <td>
    Mood:
    </td>
    <td>
    <img src="/jiemmotions/$mood.gif">
    </td>
    </tr>
    </table>
    </center>
    <p>";
    fwrite( $file, $string );
    fclose( $file );
    ?>
    <html>
    <head>
    <title>Orenji's Blog Updating system</title>
    </head>
    <body>
    <?php
     
    if( file_exists( $filename ) )
     
    echo("Done now what do you want to do next?");
     
    else { echo( "Error Problem occured please contact 
     
    Daniel" ); }
    ?>
    <br><a href="https://ichigokenkyuujo.com/"> Back to the ichigokenkyuujo</a>
     
    </body>
    </html>
     
    Last edited:
    Code:
    <?php 
    
    $filename = "news.php";
    $file = fopen( $filename, "w");
    
    $string = "<center><table><tr><td>Posted on: $date Title: $title </td></tr><tr><td> $news </td></tr><tr><td>Currently listening to: $listen </td></tr><tr><td>Mood:</td><td>"+"<img src='/jiemmotions/"+"$mood"+".gif'>"+"</td></tr></table></center><p>";
    
    fwrite( $file, $string );
    fclose( $file );
    
    ?>
    
    <html>
    <head>
    <title>Orenji's Blog Updating system</title>
    </head>
    <body>
    
    <?php
     
    if( file_exists( $filename ) ){ 
    echo("Done now what do you want to do next?");
    } // end if
     
    else{
    echo( "Error Problem occured please contact Daniel" );
    } // end else
    
    ?>
    
    <br><a href="https://ichigokenkyuujo.com/"> Back to the ichigokenkyuujo</a>
     
    </body>
    </html>


    You mispelled "$string." That's one reason why your code wouldn't work. You would have been writing a null value to your file.

    You needed use curly braces ("{" and "}") in one line blocks of code. Or be consistant, and use them around all blocks of code.

    When you declare the value of a string, it should be all on one line.

    I see variables being referenced that were not declared. Either you have some complex system going (and I would need to see all the source files to put it into context), or you need to read from another file to get those values.

    I've just fixed the noticable errors of this file. There may be deeper errors in your code that I cannot see just by looking at one file.

    Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/pichunet/public_html/ichigokenkyuujo/Blog/added.php on line 32

    This error has to so with your bad string. You need to concatenate your strings, or put them all on one line.
     
    Code:
    $string = "<center><table><tr><td>Posted on: $date Title: $title </td></tr><tr><td> $news </td></tr><tr><td>Currently listening to: $listen </td></tr><tr><td>Mood:</td><td>"+"<img src='/jiemmotions/"+"$mood"+".gif'>"+"</td></tr></table></center><p>";
    Here's your problem. You need to escape the quotation marks or it'll give an error. Change it to this:
    Code:
    $string = "<center><table><tr><td>Posted on: $date Title: $title </td></tr><tr><td> $news </td></tr><tr><td>Currently listening to: $listen </td></tr><tr><td>Mood:</td><td>\"+\"<img src='/jiemmotions/\"+\"$mood\"+\".gif'>\"+\"</td></tr></table></center><p>";
     
    I tested the code out, and Pikachu3228's code added unnecessary plus signs and quotations marks. Since PHP seems not to like concatenation as I have done it, try using this code instead:

    Code:
    $string = "<center><table><tr><td>Posted on: $date Title: $title </td></tr><tr><td> $news </td></tr><tr><td>Currently listening to: $listen </td></tr><tr><td>Mood:</td><td><img src=\"/jiemmotions/$mood.gif\"></td></tr></table></center><p>";
     
    Thanks it worked great! Thanks for the help!
     
    HellishHades said:
    I tested the code out, and Pikachu3228's code added unnecessary plus signs and quotations marks. Since PHP seems not to like concatenation as I have done it, try using this code instead:
    Please check the original code before accusing me of such things. For one, I did not add the plus signs, they were there already. And two, I did not add any quotation marks either!! I simply added the backslahses to it to escape the quotation marks in place where necessary. The code segment that came with the quote from the post is almost identical to the fix I posted!
     
    Pikachu3828 said:
    Please check the original code before accusing me of such things. For one, I did not add the plus signs, they were there already. And two, I did not add any quotation marks either!! I simply added the backslahses to it to escape the quotation marks in place where necessary. The code segment that came with the quote from the post is almost identical to the fix I posted!

    I'm sorry if that's how you interpretted my post. I only did that for simplicity's sake, so it would be easier for sableye to understand. You were right regarding the code, and I was wrong.

    I coded it that way, as that's how C++ would need it coded: you can't put variables in quotation marks at all. I wasn't sure how PHP would interpret it, so I separated the variable from quoation bits.

    Sorry again,
    Hellish
     
    HellishHades said:
    I'm sorry if that's how you interpretted my post. I only did that for simplicity's sake, so it would be easier for sableye to understand. You were right regarding the code, and I was wrong.
    i take that as a insult because i am quite a acomplished coder and i had trouble with this cose i was trying something new.
     
    I wrote the bad portion of code, but it was in Pikachu3828's post. I referred to it as his code, since it was in his post. If I had said it was my code that was bad, it could be interpretted as any/all of the previous code I had posted. I meant that I had simplified what I had said for organisational purposes, not coding purposes.

    I did not mean to demean your programming skills. I simply posted that way so it would be easiy to differenciate between the posts and the subtle differences between the code. In addition, if anyone ever comes across a similar problem and reads this thread, I wouln't want that person to misinterpret what I had posted. I don't mean to insult anyone when I post. Unfortunately, it's difficult to tell the context of a post on a forum; especially in my posts, since I avoid smiley faces like the plague.

    Sorry,
    Hellish
     
    sableye said:
    apoligie excepted and can you tell me how you would make it so that if you added another update the previous update dose not get delete because at the moment it is.
    if you want to see the pages it is one its here https://ichigokenkyuujo.pichunetwork.com/Blog/blog.php
    here
    https://ichigokenkyuujo.pichunetwork.com/Blog/add.php
    and here
    https://ichigokenkyuujo.pichunetwork.com/Blog/added.php
    feel free to test it and tell me how you would go about stopping the above thing happeneing

    1. Read whats in your current update file.
    2. Take it in as a string into your PHP writing file.
    3. Concatenate the string with the value of what you want to add ($total=$old."\n\n".$new).
    4. Update your news page with the total string.

    /or/

    Title all update-files in a date format, according to the date and time they were created (you need the time, otherwise if there are two updates in one day, one will be overwritten). Use a for loop to find the files (from the starting date of your blog to the current date plus a bit (maybe a day) to avoid timzone errors), and display the most current one on your news page. Archive all the files in another page that reads find all the files.

    The first option is less invasive. PHP uses the period to concatenate strings, just as C++ uses the plus sign to concatenate strings.

    Edit: Personally, I would go with the second option. It's more efficient, and more organised.

    Code:
    $word="real";
    $word.="ly";
    
    $word="real"."ly";
    
    //  Both give "really"
    // I would have thought PHP would use plus signs.
     
    Back
    Top