PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old October 29th, 2002, 03:37 AM
vlad_k vlad_k is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Croatia
Posts: 13 vlad_k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy PHP newbie in trouble

Hello!

I am a PHP newbie, but C/C++ guru and I am having some
trouble with a first piece of PHP code I've ever written.

Namely, the script starts with some HTML tags, and then switches
to PHP routines that check variables passed to script via
$_GET...

However, the script doesn't work. Actually, nothing gets printed
in the browser, not even the beginning HTML tags (title, and some
<centered> text)...

I don't know where to begin. I've included a custom error handler functions (copied from PHP manual), but still nothing gets printed.

I am also using MySQL functions.

The PHP parser is 4.2, running on FreeBSD platform. Other,
simpler PHP scripts run smoothly (simple echoing etc...)

The code is short (a test to MySQL/PHP login system)... perhaps
someone would be nice enough to view it?

Thanks in advance!

Reply With Quote
  #2  
Old October 29th, 2002, 05:27 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
post the code here or upload a copy of it with the file extension .phps (which allows us to see the code color coded for easy viewing). we'll be glad to help
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #3  
Old October 29th, 2002, 05:04 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
yeah, could we see your code, so we can try and figure out whats gone wrong?

Reply With Quote
  #4  
Old October 29th, 2002, 11:52 PM
vlad_k vlad_k is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Croatia
Posts: 13 vlad_k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post The code in question...

Hello fellahs!

Here is the code: Feel free to gloat over newbie mistakes and
make fun of me...

(by the way, couldn't upload a phps file)

Sorry, but message editor seems to have cut off the tabs!

PHP Code:
<html>
<
head>
  <
title>Page title</title>
</
head>
<
body>

<
center>
<
h2>Page title</h2><P>
</
center>

<?
php

    
// redefine the user error constants - PHP 4 only
    
define ("FATAL",E_USER_ERROR);
    
define ("ERROR",E_USER_WARNING);
    
define ("WARNING",E_USER_NOTICE);

    
// set the error reporting level for this script
    
error_reporting (FATAL ERROR WARNING);

    
$old_error_handler set_error_handler("myErrorHandler");

    
# -----------------------------------------------------------------


    
$dbmysql_connect ("server""user""password") or die("Could not reach database.");
    
mysql_select_db("dbase") or die("Could not select database.");

    
$action$_GET["action"];
    
$usrid$_SESSION["id"];
    
$pass$_SESSION["valid"];

    if (!
$action || !$usrid || !$pass) {
       if (
$action=="login"page_login();
       else 
page_intro();
    } else {
       
$resultmysql_query("SELECT count(id) FROM sometable WHERE id='$userid' AND pswd='$pass'") or die("Could not query database.");
       
$nummysql_result($result0);
       if (!
$num) {
             echo 
"<font color=\"#FF0000\"><P>Invalid authentication!</font><P>";
             
page_intro();
       } else {
             switch(
$action) {
                 case 
"login"page_login(); break;
            case 
"logout": echo "Some logout text.<P>"page_intro(); break;
            case 
"menu"page_menu(); break;
            case 
"intro":
            default: 
page_intro();     
             }
       }        
    }

    
mysql_close($db);
?>
</body>
</html>

<?php
# ----------------------------------------------------------------------------
#  Error handling function as in PHP manual
# ----------------------------------------------------------------------------
function myErrorHandler ($errno$errstr$errfile$errline) {
  switch (
$errno) {
  case 
FATAL:
    echo 
"<b>FATAL</b> [$errno] $errstr<br>\n";
    echo 
"  Fatal error in line ".$errline." of file ".$errfile;
    echo 
", PHP ".PHP_VERSION." (".PHP_OS.")<br>\n";
    echo 
"Aborting...<br>\n";
    exit(
1);
    break;
  case 
ERROR:
    echo 
"<b>ERROR</b> [$errno] $errstr<br>\n";
    break;
  case 
WARNING:
    echo 
"<b>WARNING</b> [$errno] $errstr<br>\n";
    break;
    default:
    echo 
"Unkown error type: [$errno] $errstr<br>\n";
    break;
  }
}


# ----------------------------------------------------------------------------

function page_none() {

}
# ----------------------------------------------------------------------------

function page_menu() {
    echo 
"Some text in protected area. <a href="testadmin.php?action=logout">Logout</a>";
}
# ----------------------------------------------------------------------------

function page_login() {
    
session_unset();

    
$usrnaddslashes($_POST["usr"]);
    
$pswdmd5($_POST["pwd"]);

    
$resultmysql_query("SELECT count(id) FROM sometable WHERE pswd='$pswd' AND username=$usrn") or die("Could not query database.");
    
$nummysql_result($result0);
    
    if (!
$num) {
       echo 
"<font color=\"#FF0000\"><P>Invalid username/password combination.</font><P>";
       
page_intro();
    } else {
       
$resultmysql_query("SELECT * FROM sometable WHERE pswd='$pswd' AND username=$usrn");    
       
$rowmysql_fetch_object($result);
       
$id$row->id;
       
$name$row->name;
       echo 
"<P>Welcome $name<P>.";

       
session_start();   
       
$_SESSION["id"]= $id;
       
$_SESSION["valid"]= $pswd;
       
       
page_menu();            
    }    
}
# ----------------------------------------------------------------------------

function page_intro() {
    
session_unset();
?>

<center>
<BR>
Some notification text.
<P>
<form method="POST" action="admin/testadmin.php?action=login">
Username:<BR>
<input type="text" name="usr" value="" size="20" maxlength="20"><P>
Password:<BR>
<input type="password" name="pwd" value="" size="20" maxlength="20"><P>
<input type="submit" value="Login">
</form>
</center>

<?php
}

?> 

Last edited by vlad_k : October 30th, 2002 at 12:07 AM.

Reply With Quote
  #5  
Old November 4th, 2002, 12:27 AM
vlad_k vlad_k is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Croatia
Posts: 13 vlad_k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy PHP newbie still in trouble!

Hello!

You've forgotten about me.

Reply With Quote
  #6  
Old November 4th, 2002, 12:39 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
so what doesnt it do? what error messages do you get?

Reply With Quote
  #7  
Old November 4th, 2002, 01:13 AM
vlad_k vlad_k is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Croatia
Posts: 13 vlad_k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face Embarrased

Uhm, I am sooooo embarrased!

I forgot to escape the slashes in an echo call....

Please forgive me wasting your time...

Is there a Win32 PHP interpreter so I could test my scripts
thoroughly before posting them online?

Last edited by vlad_k : November 4th, 2002 at 01:21 AM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP newbie in trouble


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway