Superman702 Posted August 8, 2011 Share Posted August 8, 2011 Okay. Thanks to other who helped me so far. I am almost done, but totally confused with this timestamp issue and MySQL. I haven't used HTML in awhile and decided to jump into PHP. I like PHP because it reminds me of C++, but please bare with me with the newbie questions. I have three files: test php: <html> <head> <title>PHP Test Page</title> </head> <body> <form action="process.php" method="post"> Message: <input type="text" name="Main"><br> <input type="submit" value="Submit"> </form> </body> </html> process.php <? $Main=$_POST['Main']; mysql_connect("*****", "*****", "*****") or die(mysql_error()); mysql_select_db("*****_test") or die(mysql_error()); mysql_query("INSERT INTO `Message` VALUES ('$Main')"); Print "Your message will now be broadcasted."; ?> admin.php <HTML> <HEAD> <TITLE>v2.0</TITLE> <meta http-equiv="refresh" content="20"> </head> <BODY> <?php // Connects to your Database $link = mysql_connect("*****", "*****", "*****"); mysql_select_db("*****_test", $link); $result = mysql_query("SELECT * FROM Message", $link); $num_rows = mysql_num_rows($result); if($num_rows == 0){ echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER>LA</CENTER></td>"; echo "<td width=\"80%\"><CENTER>Order Menu</CENTER></td>"; echo "<td><CENTER>Blank</CENTER></td>"; echo "</TR></table>"; } else{ $info = mysql_fetch_assoc($result); echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER>LA</CENTER></td>"; echo "<td width=\"80%\" bgcolor=\"red\"><marquee behavior=\"scroll\" direction=\"left\"><B>IMPORTANT MESSAGE: </B>".$info['Main'] . "</marquee></td>"; echo "<td><CENTER>Blank</CENTER></td>"; echo "</TR></table>"; } ?> </BODY> </HTML> MySQL 2.11.4 Message = Table Name Main varchar(500) = column #1 TimeStamper (datetime) = column #2 I want the current time of the submission of the form to be included with process.php, but I have no idea what I am doing with this whole time() function. I don't have it in the example above, but it was a mess and I guess I made up a lot of stuff that MySQL hasn't heard of before. What do I need to add to process.php to include a datetime value for Timestamper? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 time will basically return the number of seconds that have passed since 1st Jan 1970. You can convert any timestamp into other date formats using date, but if all you want is to store the time of the operation in your database, you can also use a mysql timestamp (that will automatically update the field for you, no extra code needed. Quote Link to comment Share on other sites More sharing options...
Superman702 Posted August 8, 2011 Author Share Posted August 8, 2011 When I submit the form, no entry is created. The form seems to have went thru with no errors, but when I check the table it says: MySQL returned an empty result set (i.e. zero rows). (Query took 0.0001 sec) However, if I remove the Timestamper column, the form does submit and an entry is created. Just of course, with no timestamp though. :-\ Quote Link to comment Share on other sites More sharing options...
Superman702 Posted August 8, 2011 Author Share Posted August 8, 2011 wait...I think I have something going here....just got it to go thru with this <? $Main=$_POST['Main']; $Timestamper=time(); $gettime=time(); mysql_connect("****", "****", "****") or die(mysql_error()); mysql_select_db("a7405553_test") or die(mysql_error()); mysql_query("INSERT INTO `Message` VALUES ('$Main', '$Timestamper')"); Print "Your message will now be broadcasted."; ?> But the value comes up with all zeros in the table. I think I am close though!!! Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 Why 2 variables doing the same thing? $Timestamper=time(); $gettime=time(); Yes, you can create your timestamp in php and send it through, but all this can also be automatic: in phpmyadmin, change field type from datetime to timestamp, and set Default value to CURRENT_TIMESTAMP, and Attributes to on update CURRENT_TIMESTAMP now your timestamp will update automatically every time a new database entry is created or modified. Quote Link to comment Share on other sites More sharing options...
Superman702 Posted August 8, 2011 Author Share Posted August 8, 2011 I forgot to delete that other var. I got rid of it now I changed the Timestamper column to Timestamper timestamp ON UPDATE CURRENT_TIMESTAMP No CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP. It still stills the default at all zeros. I am going to log into my other computer to take a print screen. I don't have that button on my labtop. Until then though, this is my new process.php file. <? $Main=$_POST['Main']; $Timestamper=time(); mysql_connect("*****", "*****", "*****") or die(mysql_error()); mysql_select_db("*****_test") or die(mysql_error()); mysql_query("INSERT INTO `Message` VALUES ('$Main', '$Timestamper')"); Print "Your message will now be broadcasted."; ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 there's nothing wrong with doing it through php, as you have, so I don't really want to waste your time too much on this. It's just a way of having things a little more automated so you don't have to script in a timestamp update every time you change stuff in the database. check out my print screen: Quote Link to comment Share on other sites More sharing options...
Superman702 Posted August 8, 2011 Author Share Posted August 8, 2011 That is how I have it....I think my MySQL database is just broken! haha Quote Link to comment Share on other sites More sharing options...
Superman702 Posted August 8, 2011 Author Share Posted August 8, 2011 So it turns out that when you use the time() function, it creates a int. rather than the timestamping code. So when I changed Timestamper to an INT rather then TIMESTAMP, I got a value. I think I found exactly what I needed. How do I get a value for TIMESTAMP I guess is what I am really trying to ask. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 you mean how do you convert the int returned from time to a date format ? instead of time you can use date like this: date("Y-m-d H:i:s"); or you can convert your timestamp to a date format with: date("Y-m-d H:i:s",$mytimestamp); check out all the options on php.net by following this link: date Quote Link to comment Share on other sites More sharing options...
Superman702 Posted August 8, 2011 Author Share Posted August 8, 2011 OH! Okay! I will try that. I got to get to bed, because I've been up all night doing this. But that makes sence though! I'll take a look at that tomorrow to see if it works. Thanks for all your help WebStyles!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.