ClanKiller.com
http://forums.clankiller.com/

Learning PHP
http://forums.clankiller.com/viewtopic.php?f=24&t=2385
Page 1 of 1

Author:  Arathorn [ Thu Jun 14, 2007 12:24 pm ]
Post subject:  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).

Author:  Pig [ Thu Jun 14, 2007 3:49 pm ]
Post subject: 

$_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>');

Author:  Satis [ Fri Jun 15, 2007 6:50 am ]
Post subject: 

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. :(

Author:  Pig [ Fri Jun 15, 2007 9:05 am ]
Post subject: 

var_dump() is also cool, especially if you are not certain if something is being set.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/