Page 1 of 1

PHP date

Posted: Sun Apr 15, 2007 9:42 pm
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]

Posted: Sun Apr 15, 2007 9:50 pm
by aaronhall
It doesn't look like $_POST['time'] was ever set in your form. You may be looking for time() and date().

Posted: Sun Apr 15, 2007 9:52 pm
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? :(

Posted: Sun Apr 15, 2007 10:04 pm
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())"; 

Posted: Sun Apr 15, 2007 10:10 pm
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?

Posted: Sun Apr 15, 2007 11:01 pm
by aaronhall

Code: Select all

ORDER BY your_date_column DESC

Posted: Mon Apr 16, 2007 10:23 pm
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]

Posted: Tue Apr 17, 2007 12:58 am
by RobertGonzalez
You need to tie the delete process to the clicking of the button.

Posted: Tue Apr 17, 2007 6:59 pm
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:

Posted: Tue Apr 17, 2007 7:22 pm
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>

Posted: Tue Apr 17, 2007 7:45 pm
by tkolbeck
Thanks a lot for all of your guys help!