I've recently started using strtotime, it's a lot easier to work with I find.
http://php.net/manual/en/function.strtotime.php
PHP Code:$ts = strtotime('1999-11-40');
echo date('Y-m-d', $ts);
I've recently started using strtotime, it's a lot easier to work with I find.
http://php.net/manual/en/function.strtotime.php
PHP Code:$ts = strtotime('1999-11-40');
echo date('Y-m-d', $ts);
Corrections to my coding/thoughts welcome.
Thanks Blue Walrus and Jshor. And yes I agree, you should write coding tutorials for a living (but it would be a bit boring don't you think).![]()
That's the entire code for the comments box/ member page. I am trying to display their comments like this.PHP Code:<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("keyboard_test") or die(mysql_error());
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{ header("Location: login.php");
}
else
{
$links = "link2.php";
}
}
}
else
{
header("Location: login.php");
}
?>
<?php
if (isset ($_POST['submit']))
{
$comment = mysql_escape_string (trim (nl2br($_POST['comment'])));
$date = time();
$cheese = "<b>$username</b> <br /><br /> $comment <br /><tr /> ";
$sql = mysql_query ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" . $_SERVER['REMOTE_ADDR']."')");
echo '<center>Your comment has been entered successfully!</center>';
echo '<center><a href="echo time.php"><br />Please click here</a></center>';
}
else
{
?>
<html>
<head>
</head>
<body>
<?php include("$links");
echo "Hey ".$username;
?>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<p><b>COMMENTS</b></p>
<?php
// POST data wasnt entered, so display the comments and comment form
// view comments from database
$sql = mysql_query ("SELECT * FROM comments") or die(mysql_error());;
while ($row = mysql_fetch_array ($sql)) {
echo $row['comments'].'<br />';
}
echo '<br /><br />
<form action="echo time.php" method="post">
Comments:<br />
<textarea name="comment" cols="40" rows="7"></textarea>
<input type="submit" value="Submit" name="submit">
</form>';
}
?>
<body style="background-color:lightgreen">
</body>
</html>
NAMEDATECOMMENT
but I'm not sure how to. Any help?
Although I'm not sure what you named the field that contains 'name' in MySQL.PHP Code:<?php
// POST data wasnt entered, so display the comments and comment form
// view comments from database
$sql = mysql_query ("SELECT * FROM comments") or die(mysql_error());;
while ($row = mysql_fetch_array ($sql)) {
echo $row['name'].'<br />';
echo $row['comments'].'<br />';
}
echo '<br /><br />
<form action="echo time.php" method="post">
Comments:<br />
<textarea name="comment" cols="40" rows="7"></textarea>
<input type="submit" value="Submit" name="submit">
</form>';
}
?>
<body style="background-color:lightgreen">
</body>
</html>
- Josh
You'll need to double line break after the name if you want an empty line.
Code:echo $row['name'].'<br /><br />';
Corrections to my coding/thoughts welcome.
What about the DATE, on the right hand side?
And I'm pretty sure , with the edited script it's still relying on this code to display the comment.
I because when I removed the $comment from $cheese, the comments stopped displaying.PHP Code:$date = time();
$cheese = "<b>$username</b> <br /><br /> $comment <br /><tr /> ";
$sql = mysql_query ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" . $_SERVER['REMOTE_ADDR']."')");
So I need to make a new column in the sql database called name and inserted them sepretly?
Bookmarks