Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2005, 03:13 AM
Registered User
 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default form submitting

having a bit of trouble getting the submit code for my forum, onclick its supposed to sumit using javascript (which works) then load the url using the php header function, at the moment the code doenst work, i can't get the syntax right!

   echo '<br><br><input type="button" value="'.$it.'" style="font-size:8px" onclick="javascript:submitit'.$ratecounter.'header (Location: index.php?page=Voting Successful)()">';

the last part 'header(Location: index.php?page=Voting Successful)()">';
is the only problem! anyone know how it should be written

 
Old January 19th, 2005, 10:32 AM
Registered User
 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cro,

I'm not completely sure about this, but I don't think you can have GET variables in the redirect. The PHP documentation doesn't really explain whether it is allowed or not. You might be able to send a variable over the redirect though, like so:

$page='Voting Successful';
header('Location: xxx');

Also, notice that you wrote 'header(Location: xxx)'. You need quotation marks inside the parenthesis: header('Location: xxx') or header("Location: xxx"), however I would recommend using single quotes ', because the php engine doesn't parse single quotes for variables, which makes your program run much faster. So, when writing strings with variables, use:

'This is a string with a '.$variable.'.'

instead of

"This is a string with a $variable."

Also, HTML standards say that you should close all tags that don't have closing tags with a '/'. For example, use '<br />' instead of '<br>' and '<img src="xxx" /> instead of '<img src="xxx">. It would be a good idea to start practicing this, as the old style is deprecated and will eventually die out. If you want to know more, I'd suggest taking a look at www.w3schools.com


 
Old January 19th, 2005, 10:37 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Just one small comment...

> I'm not completely sure about this, but I don't think you can have GET variables in the redirect.

That's not true, the redirect is simply telling the browser a new location, which can include query strings, anchors, etc.



Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old January 19th, 2005, 12:26 PM
Authorized User
 
Join Date: Jan 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, You can post all of the GET variables you want. It won't work with spaces however. You need to change your value to a one without a space, or replace them with a '+'. I am not sure how the $_GET superglobal will handle the value though. I have never needed to have a space in gets.

 
Old January 19th, 2005, 12:36 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

For spaces and other special characters, use urlencode() and urldecode(), respectfully.

http://www.php.net/urlencode
http://www.php.net/urldecode

Additionally the browser is generally pretty tolerant of spaces in GET values, so not encoding the value won't keep the application from working. ?get=Some Value just becomes ?get=Some%20Value and PHP still sees it as "Some Value".


Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old January 25th, 2005, 12:19 PM
Authorized User
 
Join Date: Jan 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to js_pandey Send a message via Yahoo to js_pandey
Default

try using objest buffering for this purpose.
i am sure it will work perfectly.

regards,
-Jay





Similar Threads
Thread Thread Starter Forum Replies Last Post
Submitting a form to a database nvillare Classic ASP Basics 2 January 27th, 2005 06:38 PM
Form Submitting cro_crx Beginning PHP 3 January 17th, 2005 01:30 PM
Submitting a form YuliaKupina Classic ASP Basics 3 June 24th, 2004 01:52 AM
Chapter 3, submitting a form YuliaKupina BOOK: Beginning ASP 3.0 1 June 23rd, 2004 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.