Page 1 of 1

DATE function trubble!!!!

Posted: Thu Jun 13, 2002 1:24 pm
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]

Posted: Thu Jun 13, 2002 5:00 pm
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.

how???

Posted: Fri Jun 14, 2002 4:47 am
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...

Posted: Fri Jun 14, 2002 6:53 am
by MattF
If you mean date in php then look at http://php.net/date for mysql look at http://www.mysql.com

Posted: Fri Jun 14, 2002 7:08 am
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

Posted: Fri Jun 14, 2002 10:32 am
by HG
thx
but I worked it out mu self...

peace