PHP date

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
tkolbeck
Forum Newbie
Posts: 10
Joined: Tue Apr 10, 2007 1:14 pm

PHP date

Post by tkolbeck »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] 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]


Hello everyone.

I am having problems with my date showing up.  In mysql database I have a row set  as $time and it is date NOT NULL.  

Here is my form:

[syntax="html"]<br><b><a NAME="ADD">Add a message to the board:</b><br>
<form action="insert3.php" method="post">
Name:<br> <input type="text" name="first"><br>
Message:<br> <textarea name="message" rows="15" cols="45"></textarea><br><br>
<input type="Submit" value="Submit">
</form></a>
Here is my insert3.php:

Code: Select all

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
  function redireccionar() {
    setTimeout("location.href='main.php?id=tw_redireccion'", 8000);
  }
  </SCRIPT>

</head>
<BODY onLoad="redireccionar()">

</body>
</html>

<?
$username="blahblah";
$password="blahblah";
$database="blahboobooblah";

$first=$_POST['first'];
$message=$_POST['message'];
$time=$_POST['time'];

mysql_connect("blahboobooblah",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO blog VALUES ('','$first','$message','$time')";
mysql_query($query);

mysql_close();

echo "Thank You, <b>$first</b> your message was added to the administrator board.";
echo "<br><br>";
echo "$time";

?>

If you dont redirect in 5 seconds please click <a href="#">here</a>
when I call the $time all I get is 0000-00-00


Sorry if this makes no sense at all Bu t I appreciate your time.
Thanks,
TK


Everah | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] 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
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

It doesn't look like $_POST['time'] was ever set in your form. You may be looking for time() and date().
tkolbeck
Forum Newbie
Posts: 10
Joined: Tue Apr 10, 2007 1:14 pm

Post by tkolbeck »

that is what i thought that it was somethin gwith setting it in the form but I dont know how? Can someone help me with that? :(
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Forms don't automatically send the date. If you need only the current date and time, adjust your query:

Code: Select all

$query = "INSERT INTO blog VALUES ('','$first','$message',NOW())"; 
tkolbeck
Forum Newbie
Posts: 10
Joined: Tue Apr 10, 2007 1:14 pm

Post by tkolbeck »

When I make a new message it goes under the last one. Is ther a way with the id to make it go the other way so it puts the new post on top?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Code: Select all

ORDER BY your_date_column DESC
tkolbeck
Forum Newbie
Posts: 10
Joined: Tue Apr 10, 2007 1:14 pm

Post by tkolbeck »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] 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]


One last question, with my code how would I code a button so I can just click it to delete a post and it deletes from the mysql table?


Here Is the code that shows the information:

Code: Select all

$i=0;
while ($i < $num) {

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Extra: $fax<br>E-mail: $email<br>Web: $web<br><br><hr color=saddlebrown><br><br>";

$i++;
}
if ($i == 0)
{
echo "There are no wholesale forms currently filled out";
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] 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
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You need to tie the delete process to the clicking of the button.
tkolbeck
Forum Newbie
Posts: 10
Joined: Tue Apr 10, 2007 1:14 pm

Post by tkolbeck »

Ok can someone tell me how to do that or give me a link to a tutorial about how to do this? :cry:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

tkolbeck wrote:Ok can someone tell me how to do that or give me a link to a tutorial about how to do this? :cry:

Code: Select all

<?php
if (!empty($_POST))
{
    if (isset($_POST['delete_this']))
    {
        if (isset($_POST['hidden_value']))
        {
            echo 'I tried to hide ' . $_POST['hidden_value'];
        }
        else
        {
            echo 'This did not work as it was supposed to.';
        }
    }
}
?>
<form id="my-form" action="<?php echo basename(__FILE__); ?>" method="post">
<input type="hidden" name="hidden_value" value="creamymonkeysnot" />
<input type="submit" name="delete_this" value="What happens when you click me?" />
</form>
tkolbeck
Forum Newbie
Posts: 10
Joined: Tue Apr 10, 2007 1:14 pm

Post by tkolbeck »

Thanks a lot for all of your guys help!
Post Reply