Jump to content

anybody can solve this problem


doforumda

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.