Jump to content


Photo

Newbie Question


  • Please log in to reply
5 replies to this topic

#1 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 31 March 2006 - 03:46 AM

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.



#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 31 March 2006 - 03:58 AM

post your code.


Examples only.


if($submit){
}

if(isset($submit){
}


if ($_Post($submit)) {
}




Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 31 March 2006 - 07:02 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#4 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 31 March 2006 - 09:31 PM

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)

#5 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 01 April 2006 - 09:44 AM

[!--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) View Post[/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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#6 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 01 April 2006 - 04:17 PM

[!--quoteo(post=360576:date=Apr 1 2006, 04:44 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Apr 1 2006, 04:44 AM) View Post[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users