Jump to content

Archived

This topic is now archived and is closed to further replies.

Chris Coin

Newbie Question

Recommended Posts

Been tryin out php for a couple days now, ive managed to create a link form that prints to another php file and is displayed on the same page as the form.

Problem is when the page loads it submits an empty entry.

Ive searched the net and found some complicated solutions. Was hoping to find somthing easy since im just starting.

Id also like to know if it is possible to use if ($submit) to preform the rest of the code,
What i mean is once the submit button was pressed then it would perform the rest of the php i.e send the form.

I figure if this is possible then the form wouldnt be sent untill the submit button was pressed. Therfore no empty entries on page load.

Thanks for the help.

Share this post


Link to post
Share on other sites
post your code.


Examples only.

[code]

if($submit){
}
[/code]

[code]
if(isset($submit){
}
[/code]

[code]

if ($_Post($submit)) {
}

[/code]


Share this post


Link to post
Share on other sites
if (isset($_REQUEST['submit']))
if (isset($_GET['submit']))
if (isset($_POST['submit']))

This is the format you are looking for. Make sure that you put <input type="submit" id="submit" name="submit" value="Whatever" /> as this is the proper way to make sure submit sends a value. This is for compatibility with older browsers and xhtml standard compliance.

I would suggest using if ($_SERVER['REQUEST_METHOD'] == "POST") provided that your form method will be "POST". If you use "GET" method this will not work because if you simply browse to a page the method will be "GET".

I hope this helps.

Share this post


Link to post
Share on other sites
Thanks alot, This was exactly wut i was missing

i have another question, if i wanted to say something like:

if $name is "something" then (perform this command)

for example in a form:
if the name section of the form is filled out with the name CHRIS then (do this task)

Share this post


Link to post
Share on other sites
[!--quoteo(post=360480:date=Mar 31 2006, 03:31 PM:name=Chris Coin)--][div class=\'quotetop\']QUOTE(Chris Coin @ Mar 31 2006, 03:31 PM) [snapback]360480[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks alot, This was exactly wut i was missing

i have another question, if i wanted to say something like:

if $name is "something" then (perform this command)

for example in a form:
if the name section of the form is filled out with the name CHRIS then (do this task)
[/quote]

Well that depends on the method so...

if ($_SERVER['REQUEST_METHOD'] == "POST") $name = $_POST['name'];
if ($_SERVER['REQUEST_METHOD'] == "GET") $name = $_GET['name'];

That just setup our variable depending on whether you use method GET or POST, alternatively you could use $name = $_REQUEST['name'];....

if (strtolower($name) == "chris") {
// Do some stuff
} elseif (strtolower($name) == "john") {
// Do something else
} else {
// Do something else because none of our conditions ever got met
}

I use strtolower so the condition is met even if the person typed "ChRiS" in your form. Personally I wouldn't use $name at all. I would just do...

if (strtolower($_POST['name']) == "chris") // Call Function

This assumes you have a function created to perform your tasks and you are using POST method, but this gives you an idea and hopefully answers your question satisfactorily.

Share this post


Link to post
Share on other sites
[!--quoteo(post=360576:date=Apr 1 2006, 04:44 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Apr 1 2006, 04:44 AM) [snapback]360576[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Well that depends on the method so...

if ($_SERVER['REQUEST_METHOD'] == "POST") $name = $_POST['name'];
if ($_SERVER['REQUEST_METHOD'] == "GET") $name = $_GET['name'];

That just setup our variable depending on whether you use method GET or POST, alternatively you could use $name = $_REQUEST['name'];....

if (strtolower($name) == "chris") {
// Do some stuff
} elseif (strtolower($name) == "john") {
// Do something else
} else {
// Do something else because none of our conditions ever got met
}

I use strtolower so the condition is met even if the person typed "ChRiS" in your form. Personally I wouldn't use $name at all. I would just do...

if (strtolower($_POST['name']) == "chris") // Call Function

This assumes you have a function created to perform your tasks and you are using POST method, but this gives you an idea and hopefully answers your question satisfactorily.
[/quote]


This is perfect, it gives me a good base to start.

Does anyone know of a site that will show me the basic commands wut they do and how to write them.
somthing like a PHP for dummies. Goin to the official PHP site doesnt help me at all, i need some basic rules and commands just to get me started.

Thanks.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.