doforumda Posted August 22, 2008 Share Posted August 22, 2008 dear friends i am creating a posting website. the problem i am facing is that, when the user post a new post, it will be added to the database along with todays time and date so the problem is it does add the post to the database but not adding any date and time so pleasee help me how can i do this if you need code then i ll add the as well thanks in advance Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/ Share on other sites More sharing options...
jjmusicpro Posted August 22, 2008 Share Posted August 22, 2008 In you insert statment are you using now() to get date? What is the column type you are adding this date field to>? Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/#findComment-622953 Share on other sites More sharing options...
doforumda Posted August 22, 2008 Author Share Posted August 22, 2008 column name is created_at and column type is DATETIME Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/#findComment-622959 Share on other sites More sharing options...
shotos Posted August 22, 2008 Share Posted August 22, 2008 have u checked this posting? http://www.phpfreaks.com/forums/index.php/topic,213142.0.html Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/#findComment-622975 Share on other sites More sharing options...
doforumda Posted August 22, 2008 Author Share Posted August 22, 2008 i checked it but dont get any clue here is my posts.html page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {font-size: 10px} .style2 {font-size: 18px} .style3 {font-size: 36px} .style4 {font-size: 24px} --> </style> </head> <body> <form id="form1" name="form1" method="post" action="posts.php"> <table width="200" border="0"> <tr> <td><span class="style4"> <label for="title"><strong>Title</strong></label> </span></td> </tr> <tr> <td><input name="title" type="text" id="title" size="30" maxlength="150" /></td> </tr> <tr> <td> </td> </tr> <tr> <td><span class="style1"> <span class="style2"> <span class="style3"> <span class="style4"> <label for="body"><strong>Body</strong></label> </span> </span> </span> </span></td> </tr> <tr> <td><textarea name="body" id="body" cols="45" rows="5"></textarea></td> </tr> <tr> <td><input name = "users[id]" value = "1" type = "hidden"></td> </tr> <tr> <td><input name = "<?php today = now() ?>" value = "1" type = "hidden"></td> </tr> <tr> <td><label for="submit"></label> <div align="right"> <input type="submit" name="submit" id="submit" value="Add Post" /> </div></td> </tr> </table> </form> </body> </html> when the user enter the title and body of the post with this date should also be added into to the database. Following is my posts.php page <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {font-size: 10px} .style2 {font-size: 18px} .style3 {font-size: 36px} .style4 {font-size: 24px} --> </style> </head> <body> <?php if(!$logged_in_user) { echo "Sorry you are not logged in please log in before posting any post.<br><br>"; echo "<a href = 'login.php'>Click Here</a> to login.<br><Br>"; echo "If you are not register user then please register<a href = 'register.php'> HERE </a> and then login."; exit; } if($title && $body) { $db = mysql_connect("localhost"); mysql_select_db("posts",$db); $query = "insert into posts(title, body, created_at, user_id) values('".$title."','".$body."','".$today."','".$post[user_id]."')"; $result = mysql_query($query); //echo $today; echo "Your post has been added.<br><Br>"; echo "<a href = 'posts.html'>Click here </a>to post another post.<br><Br>"; echo "<a href = 'main.php'>Click here </a>to the main page.<br><Br>"; } else if($title || $body) { echo "Please give both title and body.<br><br>"; echo "Go <a href = 'posts.html'>Back.</a>"; } ?> </body> </html> so after adding title, post's body and date and time to the database it will be echoed on the main page of the site. now how can i use date and time function in above codes which should add date and time Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/#findComment-622991 Share on other sites More sharing options...
revraz Posted August 22, 2008 Share Posted August 22, 2008 Why use a variable for the date/time when you can just use NOW() ? Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/#findComment-622998 Share on other sites More sharing options...
doforumda Posted August 22, 2008 Author Share Posted August 22, 2008 i used this variable for posts.php the date will be saved in this variable and php script will insert it into db. i also checked it without variable still not working. you modify my code for now function and repost it. Link to comment https://forums.phpfreaks.com/topic/120855-anybody-can-solve-this-problem/#findComment-623005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.