NEWS funktion problem.....

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

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

NEWS funktion problem.....

Post by HG »

I have a problem... if annyone can solve it plez let me now...

Code: Select all

Notice: Use of undefined constant localhost - assumed 'localhost' in D:\webb\hgtwo\news\db.inc.php on line 6

Notice: Use of undefined constant root - assumed 'root' in D:\webb\hgtwo\news\db.inc.php on line 7

Notice: Use of undefined constant hg - assumed 'hg' in D:\webb\hgtwo\news\db.inc.php on line 8

Notice: Use of undefined constant hgnews - assumed 'hgnews' in D:\webb\hgtwo\news\db.inc.php on line 9

Notice: Use of undefined constant admin - assumed 'admin' in D:\webb\hgtwo\news\db.inc.php on line 10

Notice: Use of undefined constant groups - assumed 'groups' in D:\webb\hgtwo\news\db.inc.php on line 11

Notice: Use of undefined constant news - assumed 'news' in D:\webb\hgtwo\news\db.inc.php on line 12

Notice: Use of undefined constant news_comments - assumed 'news_comments' in D:\webb\hgtwo\news\db.inc.php on line 13

Notice: Use of undefined constant news_logged - assumed 'news_logged' in D:\webb\hgtwo\news\db.inc.php on line 14

Notice: Use of undefined constant partners - assumed 'partners' in D:\webb\hgtwo\news\db.inc.php on line 15

Notice: Use of undefined constant pnews - assumed 'pnews' in D:\webb\hgtwo\news\db.inc.php on line 16

Notice: Use of undefined constant smileys - assumed 'smileys' in D:\webb\hgtwo\news\db.inc.php on line 17

Notice: Use of undefined constant topic - assumed 'topic' in D:\webb\hgtwo\news\db.inc.php on line 18

Notice: Use of undefined constant users - assumed 'users' in D:\webb\hgtwo\news\db.inc.php on line 19

Notice: Use of undefined constant weekQ - assumed 'weekQ' in D:\webb\hgtwo\news\db.inc.php on line 20

Notice: Use of undefined constant WeekA - assumed 'WeekA' in D:\webb\hgtwo\news\db.inc.php on line 21
this is my problem in the news funktion...

Code: Select all

Notice: Undefined index: do_what in D:\webb\crookz\guestbook\sign.php on line 8

Notice: Undefined index: action in D:\webb\crookz\guestbook\sign.php on line 33
this is the problem in the guestbook


plez help me!!!!!! 8O
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Looks like you might have arrays where you've got,

Code: Select all

$arrayїtext]
or loop conditionals like

Code: Select all

if ($this == something) {
If you have try changing these to something like

Code: Select all

$arrayї'text']
if ($this == 'something') {
And you may also be needing to read this

Although I can't say anything for sure without seeing any code...

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

ok..

Post by HG »

thx... here is the code... I´m a newbi...

Code: Select all

<?
$db_server = localhost;
$db_uname  = root;
$db_pass   = hg;
$db_name   = hgnews;
$db_admin  = admin;
$db_groups = groups;
$db_news   = news;
$db_news_comments = news_comments;
$db_news_logged = news_logged;
$db_partners = partners;
$db_pnews  = pnews;
$db_smileys = smileys;
$db_topic  = topic;
$db_users  = users;
$db_weekQ  = weekQ;
$db_weekA  = WeekA;
$smileys_path  = "D:\\webb\\hgtwo\\news/gfx/smileys";
$partners_path = "D:\\webb\\hgtwo\\news/gfx/partners";
$topic_path = "D:\\webb\\hgtwo\\news/topic";
$topic_url = "./topic";
$smiley_url = "./gfx/smileys/";
$partners_url = "./gfx/partners/";
?>
hope this cane help you help me some moor.. :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

jo, no quoting.
$db_server = localhost -> $db_server = 'localhost' and so on
like $smileys_path = "D:\\webb\\hgtwo\\news/gfx/smileys";
when using "string" variables are parsed i.e.
print("path is $smileys_path");
path is D:\webb\hgtwo\news/gfx/smileys
will be printed
print('path is $smileys_path'); // no replacement
path is $smileys_path
btw. mixing \ and / in paths.....hmmm
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Try puting quotes around the values being assigned to the variables

<?
$db_server = 'localhost';
$db_uname = 'root';
$db_pass = 'hg';
...

without puting the quotes the php interpreter doesn't know they are strings and assumes they are CONSTANTS (look up php.net), but because you haven't defined any constants you get the error messages.

Mike
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

BTW, these errors are just notices which means that they don't stop the code from running, in fact you could change the level of error reporting and never see them. However, PHP would then be doing a lot of work that it doesn't need to, ie. looking for constants that don't exist and then assuming them strings so best to leave it as it is so you can sort these probs.

A good rule of thumb would be to enclose anything that's not just numbers in quotes, eg,

Code: Select all

$var1 = 'hello';
$var2 = '10%';
$var3 = 23;
$var4 = 6.4;
PHP is loosely typed which means that the following:

Code: Select all

$var1 = 12; // an integer
$var2 = '4'; // a string
$result = $var1 - $var2; // $result = 8
will work fine.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$result = $var1 - $var2; // $result = 8
pro and con of php in one line ;)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Yup, great while you're learning but very easy to get into bad habits :roll: .
Nice not having to worry about type-mismatch errors though.

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

just another problem

Post by HG »

THX every one... this worked out fine... but now I get a nother Notice
Undefined offset: 1 in D:\webb\hgtwo\news\header.php on line 23
this is the line

Code: Select all

$mpass  = $info&#1111;1];
have no idé how to fix this... plz one more helping hand... :lol:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Basically $info[1] has not been set and therefore you can't access it because it doesn't exist.

If you're trying to access the first element in an array remember that PHP starts at zero when indexing an array so,

Code: Select all

$info = array('foo', 'bar');
echo $info&#1111;0]; // prints foo
echo $info&#1111;1]; // prints bar
Of course we can only guess at what's going wrong if you don't show any code...

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

okej,,, sorry

Post by HG »

here is the code

Code: Select all

<?php
  //******************************************************************************************
  //**                                                                                      **
  //** phpNewsManager v1.30                                                                 **
  //** contact: gregor@klevze.si                                                            **
  //** Last edited: 27th.May,2002                                                           **
  //******************************************************************************************
 
function CheckLogin()
&#123;
  global $db_admin,$db_news,$db_news_comments,$db_news_logged,$db_partners,$db_pnews,$db_smiles,$db_topic,$db_users,$db_weekQ,$db_weekA;
  global $nm_user,$action,$login,$pass;
  $info = base64_decode("$nm_user");
  $info = explode(":", $info);
  if ($action == "Login")
   &#123;
    global $login,$pass;
    $info&#1111;0] = $login;
    $info&#1111;1] = $pass;
   &#125;

  $mlogin = $info&#1111;0];
  $mpass  = $info&#1111;1];
  $result = mysql_query("select passwd from $db_admin where uname='$mlogin'") or die ("<B>Error 2:</B> Invalid query");
  $passek = 0;
  if(mysql_num_rows($result)==1) 
   &#123;
    $ar = mysql_fetch_array($result);
    if ($ar&#1111;passwd] == $mpass) &#123;$passek=1;&#125; 
   &#125;
  if ($mlogin == "") &#123;$passek=0;&#125;
  return $passek;
&#125;

function ShowLogin()
&#123; 
 global $color05;
 global $db_admin,$db_news,$db_news_comments,$db_news_logged,$db_partners,$db_pnews,$db_smiles,$db_topic,$db_users,$db_weekQ,$db_weekA;
 ?>
 <FORM ACTION="login.php" METHOD=POST>
 <FONT COLOR=#<?echo $color05;?>>Login</FONT><BR>
 <INPUT TYPE="text" NAME="login" SIZE=12 MAXLENGTH=40><BR>
 Password<BR><INPUT TYPE="password" NAME="pass" SIZE=12 MAXLENGTH=40>
 <INPUT TYPE="submit" Value="login"><BR>
 <INPUT TYPE="hidden" NAME="action" VALUE="login"><BR>
 </FORM> <?
&#125;


?>
<TABLE WIDTH="796" CELLSPACING=0 CELLPADDING=0 BORDER=0 HEIGHT=65>
 <TR>
  <TD CLASS=MojText BGCOLOR=#<?echo $color02;?>>
   <A HREF="index.php"><IMG SRC="<?echo $logo;?>" BORDER=0 WIDTH=280 HEIGHT=65></A><BR>
  </TD>
  <TD BGCOLOR=#<?echo $color02;?> VALIGN=BOTTOM ALIGN=RIGHT>
   <FONT SIZE=4 COLOR=#<?echo $color03;?> FACE=Tahoma>WEB CONTROL PANEL</FONT> 
  </TD>
 </TR>
 <TR>
  <TD COLSPAN=2 HEIGHT=1 BGCOLOR=#<?echo $color01;?>>
  </TD>
 </TR>
 <TR><TD COLSPAN=2 HEIGHT=2 BGCOLOR=#<?echo $color01;?>></TD></TR>
</TABLE>

<TABLE border=0 WIDTH="795" HEIGHT=100% CELLSPACING=0 CELLPADDING=1 BORDER=0 BACKGROUND="/gfx/tile.gif">
 <TR>
  <TD WIDTH=180 VALIGN=TOP Class=MojText BGCOLOR=#FFFFFF>
   <TABLE WIDTH=150 ALIGN=CENTER CELLSPACING=1 CELLPADDING=0 CLASS=MojText>
    <TR>
     <TD COLSPAN=2 Class=MojHead>
      User Information
     </TD>
    </TR>
    <TR>
     <TD CLASS=BoxText>
      <?
      $psw = CheckLogin();
      $info = base64_decode("$nm_user");
      $info = explode(":", $info);
      if ($action=="Login") &#123; $info&#1111;0]=$login;&#125;      
      $login = $info&#1111;0];
      if ($psw == 0) &#123; ShowLogin();&#125;
      else
       &#123;
        $res = mysql_query("SELECT * from $db_admin where uname='$login'");
        $ar = mysql_fetch_array($res);
        echo "Username: <B>".$ar&#1111;uname]."</B><BR>";
	?>
	<A HREF="index.php?action=Logout"><IMG SRC="./gfx/logout.jpg" BORDER=0 ALT="Logout"></A><?
       &#125;
      ?>
     </TD>
    </TR>
   </TABLE>
   <BR><BR>
   <?if ($psw <> 0) &#123; 
   ?>
   <TABLE WIDTH=90% ALIGN=CENTER CELLSPACING=1 CELLPADDING=0 CLASS=MojText BGCOLOR=#<?echo $color03;?>>
    <TR BGCOLOR=#<?echo $color02;?>>
     <TD COLSPAN=2 Class=MojHead>
      <FONT COLOR=#<?echo $color05;?>>Manager</FONT>
     </TD>
    </TR>
    <TR BGCOLOR=#<?echo $color04;?>>
     <TD CLASS=BoxText>
      <A HREF="index.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify News">Main</A><BR>
      <A HREF="news.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify News">News</A><BR>
      <A HREF="groups.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify News">Groups</A><BR>
      <A HREF="admin.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify categories">Admin's</A><BR>
      <A HREF="pnews.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify Public News">Public News</A><BR>
      <A HREF="category.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify categories">Category</A><BR>
      <A HREF="user.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify categories">Users</A><BR>
      <A HREF="partners.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Modify partners">Partners</A><BR>
      <A HREF="poll.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Weekly Poll">Weekly Poll</A><BR>
      <A HREF="smileys.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Smileys">Smileys</A><BR>
      <BR>
      <A HREF="browse.php"><IMG SRC="gfx/docman.gif" BORDER=0 ALT="Watch news">Browse News</A><BR>
      <BR>
     </TD>
    </TR>
   </TABLE>
   <?
   &#125;?>
  </TD>
  <TD WIDTH=1 VALIGN=TOP Class=mojText BGCOLOR=#000000>
  <TD WIDTH=100% VALIGN=TOP Class=mojText BGCOLOR=#<?echo $color06;?>>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try changing this,

Code: Select all

if ($action == "Login") &#123; 
    global $login,$pass; 
    $info&#1111;0] = $login; 
    $info&#1111;1] = $pass; 
&#125;
to something like this,

Code: Select all

$info&#1111;0] = '';
$info&#1111;1] = '';
if (isset($_POST&#1111;'action']) && $_POST&#1111;'action'] == 'Login') &#123; 
    $info&#1111;0] = $_POST&#1111;'login']; 
    $info&#1111;1] = $_POST&#1111;'pass']; 
&#125;
and

Code: Select all

if ($action=="Login") &#123; $info&#1111;0]=$login;&#125;      
$login = $info&#1111;0];
to something like

Code: Select all

if (isset($_POST&#1111;'action']) && $_POST&#1111;'action'] == 'Login') &#123; 
    $info&#1111;0] = $_POST&#1111;'login'];
&#125; else &#123;
    $info&#1111;0] = '';
&#125;
$login = $info&#1111;0];
This should explain why you need to make these changes.

Mac
Last edited by twigletmac on Tue Jun 11, 2002 5:58 am, edited 2 times in total.
HG
Forum Newbie
Posts: 18
Joined: Mon Jun 10, 2002 11:40 am
Location: sweden
Contact:

this dident work..

Post by HG »

Parse error: parse error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in D:\webb\hgtwo\news\header.php on line 18
this is the error I get now.... ?

sorry if I´m stupid HG
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

:oops: Forgot a closing parenthesis - amended the code above see if trying it again is any better.

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

Post by HG »

okej... now I´m back to same problem again as before... hmm :oops:
Notice: Undefined offset: 1 in D:\webb\hgtwo\news\header.php on line 24
Last edited by HG on Tue Jun 11, 2002 6:02 am, edited 1 time in total.
Post Reply