Re: [PHP] Problem Coding a Tutorial

2003-09-08 Thread MuToGeN
Hello Stephen,

You say then hit the Sign, dammit! button, and in your script you
have ...if ($submit == Sign!)
Obviously, the problem is that else block is executed instead of
if. It's better to use some other variable to check whether the form
is filled or not, something like
...if(strlen($_REQUEST[comments])0)...
Also, the problem may be caused by register_globals turned off...

ST I found a new book for again starting out to learn PHP/MySQL Web App 
ST programming. I've begun exercises toward that end.

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

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

ST Then I typed dbconnect.php:

ST ?php
ST mysql_connect(localhost, , ---) or
ST die (Could not connect to database);
ST mysql_select_db(guest_recorder) or
ST die (Could not select database);
?

ST followed by create_entry.php:

ST html
ST head
ST titleCreate Entry/title
ST /head
ST body

ST ?php
ST include(dbconnect.php);

ST if ($submit == Sign!)
ST {
ST $query = insert into guest_info
ST (name,location,email,url,comments) values
ST '$name', '$location', '$email', '$url', '$comments')
ST ;
ST mysql_query($query) or die (mysql_error());
?
ST h2Thanks!/h2
ST h2a href=view.phpView My Guest Book!/a/h2
ST ?php
ST }
ST else
ST {
ST include(sign.php);
ST }
?

ST and sign.php:

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

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

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

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

ST Thank you.



-- 
Best regards,
 MuToGeNmailto:[EMAIL PROTECTED]

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



Re: [PHP] Problem Coding a Tutorial

2003-09-08 Thread murugesan
This may help you.

//createenrty.php
script language=javascript
function funsubmit()
{
..
return true/false based on input checks
}
form..  onsubmit='return funsubmit()' .. action=nextpage.php
...
input type=submit name=submit value=Sign dammit
/form

//nextpage.php
do your db transactions here


-Murugesan

- Original Message - 
From: Stephen Tiano [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, September 08, 2003 3:05 PM
Subject: [PHP] Problem Coding a Tutorial


 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:
 
 ?php
 mysql_connect(localhost, , ---) or
 die (Could not connect to database);
 mysql_select_db(guest_recorder) or
 die (Could not select database);
 ?
 
 followed by create_entry.php:
 
 html
 head
 titleCreate Entry/title
 /head
 body
 
 ?php
 include(dbconnect.php);
 
 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());
 ?
 h2Thanks!/h2
 h2a href=view.phpView My Guest Book!/a/h2
 ?php
 }
 else
 {
 include(sign.php);
 }
 ?
 
 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php