Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    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.
    Get Cloud Hosting now from only£59 / month

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    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>
    Last edited by Arcticwarrio; 02-19-2013 at 01:26 PM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    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.
    Get Cloud Hosting now from only£59 / month


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •