It is currently Thu Mar 28, 2024 10:28 am



Reply to topic  [ 4 posts ] 
Learning PHP 
Author Message
Minor Diety
User avatar

Joined: Tue Apr 01, 2003 10:23 am
Posts: 3956
Location: Amsterdam
Reply with quote
Post Learning PHP
I've started to learn PHP too now, and to do that I borrowed a PHP beginners book from a friend and installed EasyPHP on my pc (EasyPHP is like WAMP but WAMP gave me issues).
After struggling through the book and doing some exercises, I wanted to make a poll in PHP. Dead simple off course, but not for me. The idea of the poll is to store the IP address into the database as well, so people can't vote twice.
The HTML part of the poll is simple:
Code:
<html>
<head>
<title>Poll</title>
</head>
<body>
<form name="poll"method="post"action="result.php">
<h3>Question:</h3>
<input type="radio"name="question"value="1">1<br>
<input type="radio"name="question"value="2">2<br>
<input type="radio"name="question"value="3">3<br>
<input type="radio"name="question"value="4">4<br>
<input type="submit" name="Send" value="Send">
</form>
</body>
</html>


But I can't figure out how I should use the result I get from poll.html in result.php. Poll.html sends an array, and according to what I found online, it's name should be $_POST, and if I put echo ("$_POST"); in result.php, the page returns Array, but if I put echo("$_POST[1]"); in results.php I get the error: "Notice: Undefined index: 1 in D:\Program Files\EasyPHP\www\peiling\result.php on line 11". How do I define the index?
The book I have and the information online weren't very helpfull (or I'm just very stupid).

_________________
Melchett: As private parts to the gods are we: they play with us for their sport!


Thu Jun 14, 2007 12:24 pm
Profile
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
$_POST is an array of everything that was in the form. What you want is:
echo( $_POST['question'] );

If you ever want to see what is inside an array, use print_r(). EG:
echo('<pre>' . print_r($_POST, true) . '</pre>');


Thu Jun 14, 2007 3:49 pm
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
yea, print_r is the coolest function ever.

print_r($_POST);
print_r($_GET);
print_r($anyarray);
print_r($evenobjects);

extremely helpful in debugging. No equivalent in c# that I've found. :(

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Fri Jun 15, 2007 6:50 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
var_dump() is also cool, especially if you are not certain if something is being set.


Fri Jun 15, 2007 9:05 am
Profile YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.