Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2006, 04:38 PM
Registered User
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help Please!!

Hi all.

I'm getting this error on my page. I'm completely new to php.

Notice: Undefined variable: theStamp in c:\Inetpub\wwwroot\neath_music\news.php on line 42
1st January 1970

Here is some of the code for the page where 'thestamp' is if this helps.

<?php require_once('Connections/con_neath_music.php'); ?>
<?php
$colname_rs_news = "-1";
if (isset($_GET['news_id'])) {
  $colname_rs_news = (get_magic_quotes_gpc()) ? $_GET['news_id'] : addslashes($_GET['news_id']);
}
mysql_select_db($database_con_neath_music, $con_neath_music);
$query_rs_news = sprintf("SELECT * FROM news WHERE news_id = %s ORDER BY news_date DESC", $colname_rs_news);
$rs_news = mysql_query($query_rs_news, $con_neath_music) or die(mysql_error());
$row_rs_news = mysql_fetch_assoc($rs_news);
$totalRows_rs_news = mysql_num_rows($rs_news);

$maxRows_rs_newslist = 8;
$pageNum_rs_newslist = 0;
if (isset($_GET['pageNum_rs_newslist'])) {
  $pageNum_rs_newslist = $_GET['pageNum_rs_newslist'];
}
$startRow_rs_newslist = $pageNum_rs_newslist * $maxRows_rs_newslist;

mysql_select_db($database_con_neath_music, $con_neath_music);
$query_rs_newslist = "SELECT * FROM news ORDER BY news_date DESC";
$query_limit_rs_newslist = sprintf("%s LIMIT %d, %d", $query_rs_newslist, $startRow_rs_newslist, $maxRows_rs_newslist);
$rs_newslist = mysql_query($query_limit_rs_newslist, $con_neath_music) or die(mysql_error());
$row_rs_newslist = mysql_fetch_assoc($rs_newslist);

if (isset($_GET['totalRows_rs_newslist'])) {
  $totalRows_rs_newslist = $_GET['totalRows_rs_newslist'];
} else {
  $all_rs_newslist = mysql_query($query_rs_newslist);
  $totalRows_rs_newslist = mysql_num_rows($all_rs_newslist);
}
$totalPages_rs_newslist = ceil($totalRows_rs_newslist/$maxRows_rs_newslist)-1;

function makeStamp($theString) {
  if (ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})", $theString, $strReg)) {
    $theStamp = mktime($strReg[4],$strReg[5],$strReg[6],$strReg[2],$strReg[3],$strReg[1]);
  } else if (ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $theString, $strReg)) {
    $theStamp = mktime(0,0,0,$strReg[2],$strReg[3],$strReg[1]);
  } else if (ereg("([0-9]{2}):([0-9]{2}):([0-9]{2})", $theString, $strReg)) {
    $theStamp = mktime($strReg[1],$strReg[2],$strReg[3],0,0,0);
  }
  return $theStamp;
}

function makeDateTime($theString, $theFormat) {
  $theDate=date($theFormat, makeStamp($theString));
  return $theDate;
}
?>

 
Old March 6th, 2006, 07:53 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

woah, you are new to php and managed to code all of this?

thats not an error. it is a notice, but you can get rid of it. I think it is referring to the "return $theStamp" line.

you can change that to

if(isset($theStamp)){
    return $theStamp;
}
else
    return null;



----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
 
Old March 6th, 2006, 07:59 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A couple things:

Not all paths return a value in your function makeStamp,
Consider adding an additional else conditional, example: if{}else if{}else if{}else{}
or consider setting $theStamp to a default value.

A "Notice" doesn't mean anything serious, instead it's giving you something to consider.

A couple links for further referrence:
    Exception Handling Levels: http://www.phpfreaks.com/forums/inde...showtopic=2139
    Notice: Undefined variable: http://forum.mamboserver.com/showthread.php?t=12133


- A.Kahtava
 
Old March 7th, 2006, 05:08 AM
Registered User
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys, but all I want to do really is sort the news items according to the date...with the newest news item becoming the default page when the user click 'Latest News'. If you take a look at http://www.neathmusic.co.uk/news.php you will see that it defaults to 'Trace Elliot Dealership'. I've tried going through the filters for the recordset in Dreamweaver but nothing works...or I get the error notice above.

I'm using two recordsets on the page and a 'Horizontal Looper' for the menu.

BTW, I didn't code the page, it's Dreamweaver 8. I couldn't even hope to do any of that.

Thanks

Antony :0)










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.