[RESOLVED] Quick PHP help please :D?
Results 1 to 9 of 9

Thread: [RESOLVED] Quick PHP help please :D?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    7

    resolved [RESOLVED] Quick PHP help please :D?

    Hi, just trying something out (im new to PHP) so far ill show you the relevant bits. Im good with html and css so nothing wrong there

    ok so:


    // top of pahe within php tags

    $region = Array ('EU', 'NON EU');




    <!-- in body -->

    <form action="" method="POST" name="region">
    <select name="region" id="select_type" onchange="document.region.submit()">
    <option> ---Please Select--- </option>
    <?php

    foreach($region as $key => $value) {

    echo '<option value="'.$key.'" .$_POST['region'] == '$key' ? 'selected' : '>'.$value.'</option>';

    }

    ?>

    </select>
    </form>



    i get this error on the page :


    Parse error: syntax error, unexpected 'region' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\xampp\Start\trial\index.… on line 86


    Not sure what to do now any help would be appreciated


    Thanks

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,876
    When posting code, please use the appropriate formatting codes described in the FAQs. As it happens, in this case doing so would have provided a clue as to your problem:

    PHP Code:
     echo '<option value="'.$key.'" .$_POST['region'] == '$key' ? 'selected' : '>'.$value.'</option>'; 
    You're missing a ' after the second " (since you haven't written any abbreviations with apostrophes, you'd expect to count an even number of them in the line - half of them opening quotes, half of them closing).
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    I knew i shouldve done that, with my haste didnt see the option...

    OK, ive changed it, i get no error now but my result (creating <option> tags from my array) isnt showing up...

    if anyone thinks its better i past my whole page let me know and ill do it.

    Thanks

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,420
    Can you show us a fixed copy of the PHP code snippet above? Also, can you show us the resulting output it generates?

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    its actually a short page ill just put it all here:

    i dont know if i wrapped the code right as its my first time so if its wrong...

    All i got on the page is 2 dropdowns the first one getting for a certain array and the second one is meant to choose an erray depending on the first one...

    PHP Code:
    <?php


    $region 
    =             Array ('EU''NON EU');
    $EUcountries =         Array( 'UK''Spain');
    $NONEUcountries =     Array( 'Austria''Australia');

    ?>

    <html>
        <head>
            <title>
            
            </title>
            
            <style>
            
            #container {
            border: 1px solid grey;
            width: 900px;
            margin: 0 auto;
            min-height: 200px;
            }
            
            .header {
            text-align: center;
            text-transform:uppercase;
            font-size: 35px;
            font-family: impact;
            color: #fff;
            background-color: grey;
            }
            
            .country {
            float: left;
            top: 30px;
            left: 30px;
            width: 200px;
            border: 1px solid grey;
            text-align: center;
            position: relative;
            }

            .select_country {
            float: left;
            left: 30px;
            top: 30px;
            width: 200px;
            border: 1px solid grey;
            position: relative;
            text-align: center;
            }

            .print {
            left: 30px;
            top: 80px;
            width: 840;
            border: 1px solid grey;
            text-align: left;
            position: relative;
            }
            </style>
        </head>

        
        
        
        
        
    <body>
    <div id="container">
        <div class="header">
        test
        </div>
            <div class="country" >
                <form action="" method="POST" name="region">
                <select name="region" id="select_type" onchange="document.region.submit()">
                <option> ---Please Select--- </option>
    <?php
    foreach($region as $key => $value){
    echo 
    '<option value="'.$key.'" '.$_POST['region'] == '$key' 'selected' '>'.$value.'</option>';
    }

    ?>
                </select>
                </form>
            </div>
            <div class="select_country">
                <form>
                    <select>
    <?php
        
    if ($_POST['region'] == '0') {
            foreach(
    $EUcountries as $key => $value){
                echo 
    '<option value="'.$key.'">'.$value.'</option>'//close your tags!!
    }
    }
    ?>
                    </select>
                </form>
            </div>
                 <div class="print">
                </div> 
    </div>
    </body>    
    <html>
    Last edited by bradgrafelman; 01-30-2013 at 11:42 AM. Reason: bbcode tags modified

  6. #6
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,420
    I don't see anything glaringly wrong, so:
    Quote Originally Posted by bradgrafelman View Post
    can you show us the resulting output it generates?

  7. #7
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,876
    The only significant issue I can see is in this line:
    PHP Code:
    echo '<option value="'.$key.'" '.$_POST['region'] == '$key' 'selected' '>'.$value.'</option>'
    The problem would manifest itself in the generated HTML. So yes, looking at that would be good.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  8. #8
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    Hi, thanks for the correction with my post bradgrafelman!

    I fixed the issue with the help of my friend.

    The issue was that line

    echo '<option value="'.$key.'" '.$_POST['region'] == '$key' ? 'selected' : '>'.$value.'</option>';

    I had to change it like this:

    echo '<option value="'.$key.'" '.(isset($_POST['region']) && $_POST['region'] == $key ? 'selected' :'').' >'.$value.'</option>';
    but not before changing the name of my form to something unique rather than it being the same as the name of my <select> tag.

    Thanks alot guys!

  9. #9
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    IM SORRY!!! but in the quick reply which formatting code do i use?? i thought the 'quote' button would do it :/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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