[PHP] How to comment out chunk of html/php mixed code?
hi, This may sound very newbie. But since html comment uses !-- -- which doesn't comment out the php code. And the php comment /**/ // apparently doesn't work on html. So how do I comment out a chunk of html/php mixed code? Many thanks, Wei Wang
[PHP] simple online form stuck at !isset($first) condition
hi, all, I have this code at http://weiwang.freeshell.org/formprac.php and the execution kept stuck at the condition part of: if(!isset($first)) { show_form(); } Even if I input some text into both field and click submit, the execution wouldn't go to any other conditional branch and be stuck at this one. Any advice would be greatly appreciated. Wei Wang !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head titleUntitled Document/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /head body h2Simple Form Example/h2 ? function show_form($first=,$last=) { ? form action=formprac.php method=POST First Name: input type=text name=first value=?echo $first? br Last Name: input type=text name=last value=?echo $last? br input type=submit /form ? } if(!isset($first)) { show_form(); } else { if(empty($first) or empty($last)) { echo You did not fill in all the fields, try againp; show_form($first,$last); } else { echo Thank you, $first $last; } } ? /body /html
Re: [PHP] simple online form stuck at !isset($first) condition
Dear Curt, Thanks a lot. Is this related to the register_global variable as well? I was stuck at the $request_method and $_SERVER['request_method'] for quite a long time. Wei - Original Message - From: Curt Zirzow [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, September 16, 2003 1:22 AM Subject: Re: [PHP] simple online form stuck at !isset($first) condition * Thus wrote Wei Wang ([EMAIL PROTECTED]): ? function show_form($first=,$last=) { ? form action=formprac.php method=POST note the method -- First Name: input type=text name=first value=?echo $first? br Last Name: input type=text name=last value=?echo $last? br input type=submit /form ? } if(!isset($first)) { make this if (!isset($_POST['first'])) { see: http://php.net/language.variables http://us3.php.net/register_globals Curt -- I used to think I was indecisive, but now I'm not so sure. -- 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
[PHP] no response from a simple php/mysql code
Hi, all, I'm a total newbie to php and just couldn't make the following php file(grabbed at awtrey.com, basic php/mysql code) running at http://weiwang.freeshell.org/guest.php I've read some php tutorials but I think I must've missed a very fundamental point that led to the failure of this code. I'd highly appreciate it if anyone could drop me a line with any advice. Many thanks, Wei Wang ? /* PHP Guestbook 1.1 Written by Tony Awtrey Anthony Awtrey Consulting See http://www.awtrey.com/support/dbeweb/ for more information 1.1 - Oct. 20, 1999 - changed the SQL statement that reads data back out of the database to reverse the order putting the newest entries at the top and limiting the total displayed by default to 20. Added the ability to get the complete list by appending the URL with '?complete=1'. Added the code and additional query to count and list the total number of entries and included a link to the complete list. 1.0 - Initial release This is the SQL statement to create the database required for this application. CREATE TABLE guests ( guest_id int(4) unsigned zerofill DEFAULT '' NOT NULL auto_increment, guest_name varchar(50), guest_email varchar(50), guest_time timestamp(14), guest_message text, PRIMARY KEY (guest_id) ); */ // This checks to see if we need to add another guestbook entry. if (($REQUEST_METHOD=='POST')) { // This loop removed dangerous characters from the posted data // and puts backslashes in front of characters that might cause // problems in the database. for(reset($HTTP_POST_VARS); $key=key($HTTP_POST_VARS); next($HTTP_POST_VARS)) { $this = addslashes($HTTP_POST_VARS[$key]); $this = strtr($this, , ); $this = strtr($this, , ); $this = strtr($this, |, ); $$key = $this; } // This will catch if someone is trying to submit a blank // or incomplete form. if ($name $email $message ) { // This is the meat of the query that updates the guests table $query = INSERT INTO guests ; $query .= (guest_id, guest_name, ; $query .= guest_email, guest_time, guest_message) ; $query .= values(,'$name','$email',NULL,'$message'); mysql_pconnect(ol.freeshell.org,weiwang,password) or die(Unable to connect to SQL server); mysql_select_db(weiwang) or die(Unable to select database); mysql_query($query) or die(Insert Failed!); echo pHello World/p; //die(after query); } else { // If they didn't include all the required fields set a variable // and keep going. $notall = 1; } } ? !-- Start Page -- HTML HEAD TITLEAdd A Message/TITLE /HEAD BODY BGCOLOR=white H1Add a Message/H1 !-- Let them know that they have to fill in all the blanks -- ? if ($notall == 1) { ? PFONT COLOR=redPlease answer all fields/FONT/P ? } ? !-- The bits of PHP in the form allow the data that was already input to be placed back in the form if it is filled out incompletely -- FORM METHOD=post ACTION=guest.php PRE Your Name: INPUT TYPE=text NAME=name SIZE=20 MAXLENGTH=50 VALUE=? echo $name; ? Your Email: INPUT TYPE=text NAME=email SIZE=20 MAXLENGTH=50 VALUE=? echo $email; ? Enter Message: TEXTAREA NAME=message COLS=40 ROWS=8 WRAP=Virtual ? echo $message; ? /TEXTAREA INPUT TYPE=submit VALUE=Add /PRE /FORM HR ? // This is where we connect to the database for reading. mysql_pconnect(ol.freeshell.org,weiwang,password) or die(Unable to connect to SQL server); mysql_select_db(weiwang) or die(Unable to select database); // This is where we count the number of entries. $query = SELECT COUNT(*) FROM guests; $numguests = mysql_query($query) or die(Select Failed!); $numguest = mysql_fetch_array($numguests); ? !-- This is where we report the total messages. -- P A HREF=guest.php?complete=1? echo $numguest[0]; ? people/A have left me a message. /P ? // This is where we decide to get all the entries or just the last 20. // This variable is set by just adding a '?complete=1' after the URL. if ($complete == 1) { $query = SELECT * FROM guests ORDER BY guest_time DESC; } else { $query = SELECT * FROM guests ORDER BY guest_time DESC LIMIT 20; } $guests = mysql_query
[PHP] more details about previous email
Hi, all, I'm a total newbie to php and just couldn't make the following php file(grabbed at awtrey.com, basic php/mysql code) running at http://weiwang.freeshell.org/guest.php I guess I didn't elaborate what the problem was. The idea of the program was simply a guest message list. And when all 3 text fields get input and Add is clicked, one entry should be put into the table guests and displayed at the bottom of the page. Now the problem is no record is inserted at all. And neither of the die() comes out. What is the problem? I've read some php tutorials but I think I must've missed a very fundamental point that led to the failure of this code. I'd highly appreciate it if anyone could drop me a line with any advice. Many thanks, Wei Wang ? /* PHP Guestbook 1.1 Written by Tony Awtrey Anthony Awtrey Consulting See http://www.awtrey.com/support/dbeweb/ for more information 1.1 - Oct. 20, 1999 - changed the SQL statement that reads data back out of the database to reverse the order putting the newest entries at the top and limiting the total displayed by default to 20. Added the ability to get the complete list by appending the URL with '?complete=1'. Added the code and additional query to count and list the total number of entries and included a link to the complete list. 1.0 - Initial release This is the SQL statement to create the database required for this application. CREATE TABLE guests ( guest_id int(4) unsigned zerofill DEFAULT '' NOT NULL auto_increment, guest_name varchar(50), guest_email varchar(50), guest_time timestamp(14), guest_message text, PRIMARY KEY (guest_id) ); */ // This checks to see if we need to add another guestbook entry. if (($REQUEST_METHOD=='POST')) { // This loop removed dangerous characters from the posted data // and puts backslashes in front of characters that might cause // problems in the database. for(reset($HTTP_POST_VARS); $key=key($HTTP_POST_VARS); next($HTTP_POST_VARS)) { $this = addslashes($HTTP_POST_VARS[$key]); $this = strtr($this, , ); $this = strtr($this, , ); $this = strtr($this, |, ); $$key = $this; } // This will catch if someone is trying to submit a blank // or incomplete form. if ($name $email $message ) { // This is the meat of the query that updates the guests table $query = INSERT INTO guests ; $query .= (guest_id, guest_name, ; $query .= guest_email, guest_time, guest_message) ; $query .= values(,'$name','$email',NULL,'$message'); mysql_pconnect(ol.freeshell.org,weiwang,password) or die(Unable to connect to SQL server); mysql_select_db(weiwang) or die(Unable to select database); mysql_query($query) or die(Insert Failed!); echo pHello World/p; //die(after query); } else { // If they didn't include all the required fields set a variable // and keep going. $notall = 1; } } ? !-- Start Page -- HTML HEAD TITLEAdd A Message/TITLE /HEAD BODY BGCOLOR=white H1Add a Message/H1 !-- Let them know that they have to fill in all the blanks -- ? if ($notall == 1) { ? PFONT COLOR=redPlease answer all fields/FONT/P ? } ? !-- The bits of PHP in the form allow the data that was already input to be placed back in the form if it is filled out incompletely -- FORM METHOD=post ACTION=guest.php PRE Your Name: INPUT TYPE=text NAME=name SIZE=20 MAXLENGTH=50 VALUE=? echo $name; ? Your Email: INPUT TYPE=text NAME=email SIZE=20 MAXLENGTH=50 VALUE=? echo $email; ? Enter Message: TEXTAREA NAME=message COLS=40 ROWS=8 WRAP=Virtual ? echo $message; ? /TEXTAREA INPUT TYPE=submit VALUE=Add /PRE /FORM HR ? // This is where we connect to the database for reading. mysql_pconnect(ol.freeshell.org,weiwang,password) or die(Unable to connect to SQL server); mysql_select_db(weiwang) or die(Unable to select database); // This is where we count the number of entries. $query = SELECT COUNT(*) FROM guests; $numguests = mysql_query($query) or die(Select Failed!); $numguest = mysql_fetch_array($numguests); ? !-- This is where we report the total messages. -- P A HREF=guest.php?complete=1? echo $numguest[0]; ? people/A have left me a message. /P
[PHP] How are variables called in current php?
hi, all, I have a piece of code stuck at the point of if (($REQUEST_METHOD=='post')). var_dump($REQUEST_METHOD); shows that the variable doesn't exist. Since I grabbed the code from a 2001 update, is there any chance that this is already obsolete? I checked the documentation but didn't find anything relevant. Any advice would be highly appreciated. ;-) The following is the complete code that I got stuck at if (($REQUEST_METHOD=='post')) { // This loop removed dangerous characters from the posted data // and puts backslashes in front of characters that might cause // problems in the database. for(reset($HTTP_POST_VARS); $key=key($HTTP_POST_VARS); next($HTTP_POST_VARS)) { $this = addslashes($HTTP_POST_VARS[$key]); $this = strtr($this, , ); $this = strtr($this, , ); $this = strtr($this, |, ); $$key = $this; } else { print ('Boo, I never got executed'); }//apparently the script never make it to this point And add appriopriate assigments at the top of your script.
[PHP] value passing from html form to php variable.
I am not sure if this is the right place to ask this naive question. I got a simple form addform.html and add.php look like the following. But everytime I got empty value from firstname and lastname. It seems like the input value in the html page was not passed on to the php variable $firstname in add.php. Anyone give me a hand on this naive question? Great thanks. Wei addform.html html body form action=add.php method=post First Name : input type=text name=firstname size=40 length=40 value=BR Surname : input type=text name=surname size=40 length=40 value=BR input type=submit name=submit value=Submit input type=reset name=reset value=Clear It /form /body /html add.php html body ?php $db = pg_connect(dbname=friends); $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), '$firstname', '$surname'); $result = pg_exec($db, $query); if (!$result) { printf (ERROR); $errormessage = pg_errormessage($db); echo $errormessage; exit; } printf (These values were inserted into the database - %s %s, $firstname, $surname); pg_close(); ? /body /html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] value passing from html form to php variable.
Do you mind telling me where this php.ini is? And I tried the second attempt like this: $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), $_POST['firstname'], $_POST['surname']); which returns error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /local/scratch-1/ww220/Apache1.3/htdocs/test/add2.php on line 5 Oy Sat, 1 Jun 2002 16:57:00 +0100 [EMAIL PROTECTED] (Stuart Dallas) wrote: On Saturday, June 1, 2002 at 4:51:20 PM, you wrote: I got a simple form addform.html and add.php look like the following. But everytime I got empty value from firstname and lastname. It seems like the input value in the html page was not passed on to the php variable $firstname in add.php. Anyone give me a hand on this naive question? You probably have register_globals turned Off in your php.ini file. If you do then you can either turn it on or use the recommended method of accessing POSTed variable: $_POST['firstname']. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] value passing from html form to php variable.
Create a php script containing just ?php phpinfo(); ?. That page will tell you where your php.ini is (or should be). it told me it's in php/lib, but it's not there. Try this... $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), .$_POST['firstname']., .$_POST['surname'].); When I input Wei for firstname and Wang for surname in the form and submit, I got error: Warning: pg_exec() query failed: ERROR: Attribute 'andras' not found in /local/scratch-1/ww220/Apache1.3/htdocs/test/add2.php on line 6 ERRORERROR: Attribute 'andras' not found ps. Philip, Great thanks for your detailed help. I still couldn't figure out how to access $firstname. And I couldn't find php.ini, which should be the most straightforward way to solve this. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] value passing from html form to php variable.
Sorry. When I input Andras as firstname in the form, ... On Sat, 1 Jun 2002 17:22:02 +0100 [EMAIL PROTECTED] (Wei Wang) wrote: Create a php script containing just ?php phpinfo(); ?. That page will tell you where your php.ini is (or should be). it told me it's in php/lib, but it's not there. Try this... $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), .$_POST['firstname']., .$_POST['surname'].); When I input Wei for firstname and Wang for surname in the form and submit, I got error: Warning: pg_exec() query failed: ERROR: Attribute 'andras' not found in /local/scratch-1/ww220/Apache1.3/htdocs/test/add2.php on line 6 ERRORERROR: Attribute 'andras' not found ps. Philip, Great thanks for your detailed help. I still couldn't figure out how to access $firstname. And I couldn't find php.ini, which should be the most straightforward way to solve this. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] value passing from html form to php variable.
Is there anything I should do to make the php.ini come into effect? I did put the register_global = On but still got empty values. And my $_POST version is like this: ?php $db = pg_connect(dbname=friends); $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), $_POST['firstname'], $_POST['surname']); $result = pg_exec($db, $query); if (!$result) { printf (ERROR); $errormessage = pg_errormessage($db); echo $errormessage; exit; } printf (These values were inserted into the database - %s %s, $firstname, $surname); pg_close(); ? /body /html On Sat, 1 Jun 2002 17:08:11 +0100 [EMAIL PROTECTED] (Stuart Dallas) wrote: On Saturday, June 1, 2002 at 5:00:18 PM, you wrote: Do you mind telling me where this php.ini is? Create a php script containing just ?php phpinfo(); ?. That page will tell you where your php.ini is (or should be). And I tried the second attempt like this: $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), $_POST['firstname'], $_POST['surname']); which returns error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /local/scratch-1/ww220/Apache1.3/htdocs/test/add2.php on line 5 Try this... $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), .$_POST['firstname']., .$_POST['surname'].); -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[4]: [PHP] value passing from html form to php variable.
Sorry. I restared apache and php.ini came into effect. On Sat, 1 Jun 2002 17:29:13 +0100 [EMAIL PROTECTED] (Stuart Dallas) wrote: On Saturday, June 1, 2002 at 5:22:02 PM, you wrote: Create a php script containing just ?php phpinfo(); ?. That page will tell you where your php.ini is (or should be). it told me it's in php/lib, but it's not there. The default php.ini is called php.ini-recommended and will be in the directory where you installed PHP. Copy it to php/lib and rename it to php.ini. When PHP can't find php.ini it uses it's built-in defaults - these set register_globals to off. When I input Wei for firstname and Wang for surname in the form and submit, I got error: Warning: pg_exec() query failed: ERROR: Attribute 'andras' not found in /local/scratch-1/ww220/Apache1.3/htdocs/test/add2.php on line 6 ERRORERROR: Attribute 'andras' not found Show us what is on line 6 and a couple of lines either side of it. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[4]: [PHP] value passing from html form to php variable.
Changed the query and get this error when input dave as firstname: ERRORERROR: Attribute 'dave' not found add2.php is: html body ?php $db = pg_connect(dbname=friends); $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), .$_POST['firstname']., .$_POST['surname'].); $result = pg_exec($db, $query); if (!$result) { printf (ERROR); $errormessage = pg_errormessage($db); echo $errormessage; exit; } printf (These values were inserted into the database - %s %s, $firstname, $surname); pg_close(); ? /body /html addform.php is: html body form action=add2.php method=post First Name : input type=text name=firstname size=40 length=40 value=BR Surname : input type=text name=surname size=40 length=40 value=BR input type=submit name=submit value=Submit input type=reset name=reset value=Clear It /form /body /html On Sat, 1 Jun 2002 17:44:57 +0100 [EMAIL PROTECTED] (Stuart Dallas) wrote: On Saturday, June 1, 2002 at 5:35:03 PM, you wrote: Is there anything I should do to make the php.ini come into effect? I did put the register_global = On but still got empty values. you may not need to do anything or you may need to restart your http server. Have a look at your phpinfo() page. If it's picking up the php.ini file then it will show it's filename as well as it's path. ?php $db = pg_connect(dbname=friends); $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), $_POST['firstname'], $_POST['surname']); $result = pg_exec($db, $query); if (!$result) { printf (ERROR); $errormessage = pg_errormessage($db); echo $errormessage; exit; } printf (These values were inserted into the database - %s %s, $firstname, $surname); pg_close(); ? /body /html Hmm, line 6 of that code would be printf (ERROR); but I'll assume that you haven't included the first few lines and that line 6 is actually the pg_exec line. You haven't changed $query as I suggested in a previous message. Change the $query = line to the following... $query = INSERT INTO friends (id, firstname, surname) values (nextval('friends_id_seq'), .$_POST['firstname']., .$_POST['surname'].); -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php