DATE function trubble!!!!

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
HG
Forum Newbie
Posts: 18
Joined: Mon Jun 10, 2002 11:40 am
Location: sweden
Contact:

DATE function trubble!!!!

Post by HG »

I have some problems with my date function... this is the mess I get!
Notice: Undefined index: date in D:\webb\crookz\news\newsupdate.php on line 37

Notice: Undefined variable: date in D:\webb\crookz\news\newsupdate.php on line 68
this is the code!

Code: Select all

<link rel="stylesheet" href="../css/tabel.css" type="text/css">
<link rel="stylesheet" href="../css/link.css" type="text/css">
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#CCCCCC">
<table width="100%" border="0">
  <tr> 
    <td height="19"><a href="formnews.php">add more news---></a></td>
  </tr>
  <tr>
    <td>
      <div align="right"><a href="news.php"><---back to main</a></div>
    </td>
  </tr>
</table>
<?php
 
 
 
$username= "root";  
 
 
 
$password= "hg"; 
 
 
 
$db= "News";  
 
$title= $_POST&#1111;'title'];
 
$summary= $_POST&#1111;'summary'];
 
$author= $_POST&#1111;'author'];
 
$story= $_POST&#1111;'story'];

$date_added= $_POST&#1111;'date'];

function make_datetime_pretty($date) &#123; 
  $break = explode(" ", $date); 
  $datebreak = explode("-", $break&#1111;0]); 
  $time = explode(":", $break&#1111;1]); 
  $datetime = date("F j, Y - g:i A", mktime($time&#1111;0],$time&#1111;1],$time&#1111;2],$datebreak&#1111;1],$datebreak&#1111;2],$datebreak&#1111;0])); 
  return $datetime;
&#125; 
 
 
 
 
$link = mysql_connect( "localhost", $username, $password )
 
 
 
   or die("unable to connect to mysql server: ".mysql_error());
 
 
 
mysql_select_db($db,$link)
 
 
 
   or die("unable to select database 'db': ".mysql_error());
 
 
 
 
 
$result = mysql_query("INSERT INTO crookznews(Title ,Summary, Author ,Story ,date_added) values ('$title','$summary', '$author', '$story', '$date')", $link);
 
 
 
if (!$result) &#123;
 
 
 
   die("query failed: ".mysql_error());
 
 
 
&#125;
 
?>
plz help me.... fustration kid![/b]
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Okay, in your query you refer to $date, where does that come from? I notice you have defined a function

function make_datetime_pretty($date)

but at no time do you call this.

You have a post variable $_POST['date'] but you assign this to $date_added, and are you sure 'date' is passed as a variable because PHP doesn't think so, hence the error undefined index 'date'. When you specify an item of an array you do so using the index, $_POST['date'] 'date' is the index in this case and PHP is telling you it doesn't exist.
HG
Forum Newbie
Posts: 18
Joined: Mon Jun 10, 2002 11:40 am
Location: sweden
Contact:

how???

Post by HG »

how do I call the date function??? it´s ment to put the date in the database... sorry but I´m new to this php stuff...
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

If you mean date in php then look at http://php.net/date for mysql look at http://www.mysql.com
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does the form look like from which you gather the data. I think that there may not be any form input box named 'date'.

Mac
HG
Forum Newbie
Posts: 18
Joined: Mon Jun 10, 2002 11:40 am
Location: sweden
Contact:

Post by HG »

thx
but I worked it out mu self...

peace
Post Reply