[PHP] Problem Understanding Code in 2nd edition Welling/Thomson PHP?MySQL Web Development Book

2003-11-08 Thread Stephen Tiano
Sorry for the long post--and the cross-posting to a MySQL list, for 
those of you seeing this a second time--but I'm using with difficulty 
the 2nd edition of Welling/Thomson's PHP and MySQL Web Development as a 
textbook for self-teaching (and I'm at the end of my rope).

After being pleased to work my way thru to Chapter 14, not memorizing 
the earlier material, but having some success basically understanding 
it--I get to the first "meaty" topic that I was really looking forward 
to getting into: the business of authentication.

So I went into MySQL and created the database auth and the table auth, 
using the following script:

create database auth;

use auth;

create table auth (
 namevarchar(10) not null,
 passvarchar(30) not null,
 primary key (name)
);
insert into auth values
('user', 'pass');
insert into auth values
( 'testuser', password('test123') );
grant select, insert, update, delete
on auth.*
to [EMAIL PROTECTED]
identified by 'rivet';
I used my username that I log into the computer I'm working on--an 
offline Powerbook--at the bottom, 'stevet', as well as the password that 
belongs to that username, 'rivet'. Since I'm using the test server 
'localhost' on the Powerbook, I used that in the code, as well. These 
have worked when called for in previous PHP/MySQL exercises, so it's not 
something new I invented just for this batch of tutorials.

Next I opened listing 14.2, secretdb.php--placed properly at the root 
level for accessing in my test server--in my browser. Here's secretdb.php:


 Please Log In
 This page is secret.
 
 
 
Username 
 
 
 
Password 
 
 
 
   
 
   
 
 
 

 // query the database to see if there is a record which matches
 $query = "select count(*) from auth where
   name = '$name' and
   pass = '$password'";
 $result = mysql_query( $query );
 if(!$result)
 {
   echo 'Cannot run query.';
   exit;
 }
 $count = mysql_result( $result, 0, 0 );

 if ( $count > 0 )
 {
   // visitor's name and password combination are correct
   echo 'Here it is!';
   echo 'I bet you are glad you can see this secret page.';
 }
 else
 {
   // visitor's name and password combination are not correct
   echo 'Go Away!';
   echo 'You are not authorized to view this resource.';
 }
}
?>
I was greeted by the Please Log In screen. I used 'user' as username and 
'pass' as the password, as that was one of the two combinations the 
first bit of code above inserted into the table auth. After submitting, 
I got the customized error message: "Go Away! You are not authorized to 
view this resource."

Just to make certain, I substituted 'root' and my root password in both 
pieces of code for 'stevet' and 'rivet', and got the same error screen.

I don't understand why either of those username/password combinations 
don't work. I mean, they're in the authorization table. And I'm 
obviously connecting to the database, as I'm getting past that stage of 
the code. Can anyone tell me what I'm too dense to see?

Thanks very much.

Steve Tiano

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Opening Files via PHP

2003-10-23 Thread Stephen Tiano
Anyone familiar with PHP AND MYSQL WEB DEVELOPMENT, 2nd edition, by Luke 
Welling and Laura Thomson? And perhaps working on the Macintosh-UNIX 
side of things via OS X.whatever? If so, I ask for your indulgence and 
assistance.

Following advice given me a coupla weeks ago--on this very list, I 
believe--I've bought it to ground myself firmly in PHP and MySQL both, 
before moving on to my platform- and HTML editor-specific choices.

In this case--not surprising, given my second question above--I'm 
learning the UNIX brand on the Macintosh OS X.whatever side of things to 
eventually work with this Dreamweaver MX I've heard is so convenient 
with which to work. That is, once I've properly learned the PHP/HTML 
underpinnings.

And so I've gotten as far as chapter two running the book's code, before 
a problem's occurred that I can't get a handle on. It's obviously 
because I'm new to the world of UNIX and its file conventions.

A file to read and write to has been provided on the book's CD. I've 
copied this file, named "oders.txt", in a folder (directory) on my hard 
drive, the path which runs like so:

   [hard drive name]/Library/WebServer/Documents/orders/orders.txt.

And the code the book uses to write to this file is:

   // open file for appending
 $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'a');
 flock($fp, LOCK_EX);

 if (!$fp)
 {
  echo ' Your order could not be processed at this 
time.  '
.'Please try again later.';
   exit;
 }

 fwrite($fp, $outputstring);
 flock($fp, LOCK_UN);
 fclose($fp);
 echo 'Order written.';

Unfortunately, my browser--Netscape 7.02--gives the following in 
response to that code:
   
   Warning: fopen(/Library/WebServer/Documents/../orders/orders.txt) 
[function.fopen]: failed to
   create stream: No such file or directory in
   /Users/stephent/Sites/php_mysql_web_dev/chapter_02/processorder.php 
on line 63

   Warning: flock(): supplied argument is not a valid stream resource
   in /Users/[name I 
use]/Sites/php_mysql_web_dev/chapter_02/processorder.php on line 65

   Your order could not be processed at this time. Please try again later.
   
Can someone point out what I need to do here to make this work?

Thank you.

Stephen Tiano

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Trying to View php.ini

2003-09-20 Thread Stephen Tiano
I'm on a Mac PowerBook. I'm able to locate the php.ini file. But when I 
open it with BBEdit, it's a blank page. I just want to open it and 
either view it, or make a copy to view. But all I have is the blank. Any 
suggestions?

Thank you.

Steve Tiano

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Need Help Troubleshooting Code That Works Till It Comes to Form at End

2003-09-14 Thread Stephen Tiano
I spent last night trying, overnight brooding (in my sleep), and this 
morning, finally, finding and fixing the errant line in the code below 
to get it to display in my browser the entries I made in a test name 
named "users".

So I got is to display every column of every entry. But when I tried a 
specialized select statement in the query box provided by the form at 
the very end of this code, when I pressed the "Submit" button, nothing 
changed; I was still left staring at the table of all the info in "users".

What am I missing in the form?

Thanks much.

Steve Tiano

--



if(!isset($query) || empty($query))
   {$query = "select * from users";}
//stripslashes is necessary because the slect statement is
//coming from a form. In most systems, the magic_quotes
//setting (see Appendix A) will prepend single quotes
//with backslashes, which could be problematic.
$query=stripslashes($query);
mysql_connect("localhost", "name", "password") or die ("Could not 
connect to database");
mysql_select_db("mysqlphp_db_apps_exerDB") or die ("Could not select 
database");
$result = mysql_query($query) or die(mysql_error() );

$number_cols = mysql_num_fields($result);

echo "query: $query";
//lay out table header
echo "\n";
echo "\n";
for ($i=0; $i<$number_cols; $i++)
{
   echo "" . mysql_field_name($result, $i). "\n";
}
echo "\n";//end table header
//lay out table body
while ($row = mysql_fetch_row($result))
{
   echo "\n";
   for ($i=0; $i<$number_cols; $i++)
   {
   echo "";
   if (!isset($row[$i])) //test for null value
   {echo "NULL";}
   else
   {echo $row[$i];}
   echo "\n";
   }
   echo "\n";
}
echo "";

?>


   
   

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Problem Coding a Tutorial

2003-09-08 Thread Stephen Tiano
Kae,

Excuse my being dense, but I just want to get your meaning with the
lines you added. You're saying to substitute

if($_POST['submit']=='Sign!')

for

if ($submit == "Sign!")

and  to try ('$_POST[name]', ...  (and not $_POST['name'])?

Thank you.

Steve Tiano

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Problem Coding a Tutorial

2003-09-08 Thread Stephen Tiano
I found a new book for again starting out to learn PHP/MySQL Web App 
programming. I've begun exercises toward that end.

So far I've opened MySQL--I'm on a Macintosh PowerBook, so that's 
UNIX--as root and created a database I called guest_recorder. Then I 
GRANTed ALL to a new user (me) with a password. I then quit MySQL.

Next I opened MySQL again as the new user I created, did a USE 
guest_recorder and then created my first table guest_info. The table had 
five columns: name, location, email, url, and comments. When I did a 
DESCRIBE guest_info, it properly displayed the columns.

Then I typed "dbconnect.php":


followed by "create_entry.php":



Create Entry



if ($submit == "Sign!")
{
$query = "insert into guest_info
(name,location,email,url,comments) values
<'$name', '$location', '$email', '$url', '$comments')"
;
mysql_query($query) or die (mysql_error());
?>
Thanks!
View My Guest Book!

and "sign.php":

When I open "create_entry.php" in my browser, the form and its five 
fields appear correctly, and I fill them out. I then hit the "Sign, 
dammit!" button.

I was expecting the "Thanks!" and "View My Guest Book!" messages, but 
instead am greeted with the same form with its five blank fields so's I 
can type in info for name, location, email, url, and comments.

When I go to view the table named "guest_info" in the database named 
"guest_recorder" using SELECT * FROM guest_info, I'm told "Empty set".

If the form's info isn't making it to the table, I'm thinking I need 
$_POST statements--as in $_POST["name"], $_POST["location"], 
etc.--somewhere to get each field's info into the table. But where do I 
put those lines and in which file: "create_entry.php" or "sign.php"?

Thank you.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Roadblock When One Page Calls ANother to Log In Users

2003-04-05 Thread Stephen Tiano
When accessing a page called "Create Users", it checks that the user 
doing just that is properly logged in--this is part of the admin section 
of the site, not the public end. If not, it sends one to a page created 
by "login.php". There one is met by instructions to type in a username 
and password, then press a button labeled "Login". Upon pressing the 
latter, a box lowers from the top of the screen; it contains the 
instruction to select a username from a list [of all the usernames I'd 
previously used in the books earlier exercise]. When I choose one, it 
and a password appear in the appropriate fields. I then press "Login" 
again and the process repeats--i.e., the fields are cleared and the box 
lowers from above with the instructions to type in a username and 
password, then press a button labeled "Login".

I'm using Netscape 7, and when I go to Tools --> Password Manager --> 
Manage Stored Passwords and clear the stored passwords, I am no closer 
to anything working. In fact, after pressing the login button after 
filling in the username and password fields produces nothing at all 
until I try a few times and some usernames accumulate and thereby send 
the window down from the top of the screen.

Would anyone be willing to take a look at the coupla files to see if 
I've messed up the code?

Thank you.

Steve Tiano

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php