Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2013, 04:40 AM   PM User | #1
jigalong
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jigalong is an unknown quantity at this point
Unhappy Pieces of code appears on page

Hi guys.
So, I'm just trying this tutorial on checkbox and whatever I check is supposed to appear on the check.php. However, it displays "; } } ?> instead. I've been trying to fix it but failed. I've checked that I saved it in .php.
Also, can anyone tell me what's ANSI? Because here, it says that I might need to save it as ANSI but I don't know how to do so because I can't find the option.
Here is my php file:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Check</title>
</head>
<body>
<?php
if ($_POST['sub']){
$check = $_POST['check'];
foreach($check as $ch){
echo $ch."<br>";
}
}
?>
</body>
</html>

Thanks in advance!
jigalong is offline   Reply With Quote
Old 02-19-2013, 01:14 PM   PM User | #2
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 581
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
try this:



with check.php as the filename

enter this:

PHP Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Check</title>
</head>
<body>
<?php
if ($_GET['sub']){
    
$check $_GET['check'];

foreach(
$check as $ch){
    
echo 
$ch."<br>";
}
}
?>
</body>
</html>
and browse to this and see what you get

PHP Code:
check.php?sub=5&check[1]=1&check[2]=test 

and what is your form script from the previous page?
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is offline   Reply With Quote
Old 02-19-2013, 01:19 PM   PM User | #3
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 581
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
also each field on you form needs to be named correctly

<input value="" name="check[]" type="text" />

not

<input value="" name="check" type="text" />

something like

PHP Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Check</title>
</head>
<body>
<form name="form1" method="post" action="">
    <input type="hidden" name="sub" value="true">
    <input type="checkbox" name="check[]" value="Yes">  Yes<br>
    <input type="checkbox" name="check[]" value="No">  No<br>
    <input type="checkbox" name="check[]" value="Maybe">  Maybe<br>
    <input type="submit" name="Submit" value="Submit">
</form>
<?php
if ($_POST['sub']){
    
$check $_POST['check'];

foreach(
$check as $ch){
    
echo 
$ch."<br>";
}
}
?>
</body>
</html>
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.

Last edited by Arcticwarrio; 02-19-2013 at 01:26 PM..
Arcticwarrio is offline   Reply With Quote
Old 02-19-2013, 01:23 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This is considered an element in HTML: <?php if ($_POST['sub']){ $check = $_POST['check']; foreach($check as $ch){ echo $ch."<br> where the start and ends are < and >. If you view your source you'll see the entire code segment. The remaining is added to the output.
You are either accessing the file without using http:// protocol, or you don't have PHP installed and configured for your webserver. You haven't indicated that you've installed a webserver for this, so I'm leaning towards this being both of the above.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-19-2013, 02:12 PM   PM User | #5
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 581
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
lol, didn't think of that Fou-Lu

you can get a mini php server here for testing on

http://www.apachefriends.org/en/xampp.html
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is offline   Reply With Quote
Reply

Bookmarks

Tags
php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:20 AM.


Advertisement
Log in to turn off these ads.