We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,657 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Php date

Hello,
I am making a php comment box (without sql with a file where i post the comments) i'd like that the the time that the comment was posted be written along with the name of the person, but it gives me the current time, here is my php code.

<?php
$act = $_POST['act'];
if($act == "post") {
    $name = $_POST 
['name'];
    $area  = $_POST ['area'];
    @$fp = fopen("comments.php", 'a');
    if (!$fp) {
        echo "There was an error! Please try again later!";
        exit;
    } else {
          $outputstring = "</br><b>" .$name.   " </b> le <?php
echo date('d/m/Y') ;
?> a <?php
echo date('G:i') ;
?> a ecris:<hr/>"  .$area. "</br>" ;



        fwrite($fp, $outputstring, strlen($outputstring));

        fclose($fp);

        //Post the success message
        header('Location: Article1.php');   
    }
} else {
    //We are not trying to post a comment, show the form.
?>
<hr/>
<p>commentaires:</p>
<?php include("comments.php"); ?>
<br><br>
<hr/>
<p>Envoyez un commentaire:</p>

<form action="Article1.php" method="post">

    <table>

        <tr>
            <td>Name:</td>
            <td><input type="text"  name="name" style="font-family:arial; font-size = 12pt" value=""></input></td>
        </tr>
        <tr>
            <td>Comment:</td>

            <td><INPUT TYPE="button" NAME="insert" VALUE="Gras" onClick="this.form.area.value=this.form.area.value.concat('<b>Ajouter votre texte en gras ici</b>');">
<INPUT TYPE="button" NAME="insert" VALUE="Souligner" onClick="this.form.area.value=this.form.area.value.concat('<u>Ajouter votre texte soulignes ici </u>');">
<INPUT TYPE="button" NAME="insert" VALUE="italique" onClick="this.form.area.value=this.form.area.value.concat('<i>Ajouter votre texte en italique ici </i>');">
<INPUT TYPE="button" NAME="insert" VALUE="lien" onClick="this.form.area.value=this.form.area.value.concat('<a href=Ajouter le lien ici>Ajouter le nom de votre lien ici</a>');">
</br>
<INPUT TYPE="button" NAME="insert" VALUE="Image" onClick="this.form.area.value=this.form.area.value.concat('<img src=Ajouter le lien de votre image ici, ne choisisez pas une image gigantesque>');">
<INPUT TYPE="button" NAME="insert" VALUE="Ork enerver!!!!!!!" onClick="this.form.area.value=this.form.area.value.concat('<img src=http://www.pixeljoint.com/files/icons/full/orko_final.gif>');">
<INPUT TYPE="button" NAME="insert" VALUE="Bad moonz" onClick="this.form.area.value=this.form.area.value.concat('<img src=http://wh40k.lexicanum.com/mediawiki/images/c/cb/Bad_Moon_Clan_banner.jpg>');">
</br>
<textarea name="area"  style="font-family:arial; font-size = 12pt" rows = "8" cols = "30" wrap="hard"></textarea><br>


</td>

        </tr>
    </table>
    <input type="hidden" name="act" value="post"></input>
    <input type="submit" name="submit" value="Envoyez"></input>
</form>



<?php
}
?>

thank you for your help in advance,
Sanchixx

3
Contributors
6
Replies
2 Days
Discussion Span
11 Months Ago
Last Updated
7
Views
Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

Where's the code for inserting data into the DB?

diafol
Keep Smiling
Moderator
10,625 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

I dont have a database the comments are inserted in a page 'comments.php' and then put on top of the comment box.

Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

$outputstring = "</br><b>" .$name. " </b> le <?php
echo date('d/m/Y') ;
?> a <?php
echo date('G:i') ;
?> a ecris:<hr/>" .$area. "</br>" ;

I think what you want is something like this

$outputstring = "</br><b>" .$name.   " </b> le ".date('d/m/Y')." a ".date('G:i')." a ecris:<hr/>"  .$area. "</br>" ;

to add the date at time of posting to your output string.

Hearth
Posting Whiz in Training
298 posts since Apr 2008
Reputation Points: 123
Solved Threads: 44
Skill Endorsements: 4

Thank you it works :D
But how do i change the time zone to the the time on a users computer, I know you can do it in javascript can you do it in php?

Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

You need to use the DateTime class. See setTimezone function examples.

Hearth
Posting Whiz in Training
298 posts since Apr 2008
Reputation Points: 123
Solved Threads: 44
Skill Endorsements: 4

It works!

Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1128 seconds using 2.66MB