SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unexpected "[" expected "]"

    Hi..guys! what wrong with the code?
    PHP Code:
    $name = $_GET[time[<?php echo $rows['name']]];
    It indicated that Unexpected "[" expected "]" syntax error.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What's the code trying to do?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    if (isset($_SESSION['gmemberid'])) {

        
    $tbl_name "movie";
        
    $result mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s
                 LIMIT 7'
    $tbl_name)) or die('Cannot execute query.');


        
    //$numrow = mysql_num_rows($result);


        
    while ($rows mysql_fetch_assoc($result)) {
            echo 
    '<table width="100%" border="0"><tr><td height="68">
                      <table width="100%" height="47" border="0">
                       ---------------------------------------------------------------------------------------------------------<br>'
    ;

            echo 
    '<strong>' $rows['name'] . ' (' $rows['classification'] . ')
                     <br></strong>'
    ;
            foreach (
    explode(','$rows['screeningTime']) as $time) { ?>
                <label>
                <input type="radio"  name="time[<?php echo $rows['name']; ?>]"
                  title ="screening time" value="<?php echo $time?>">
                 <input type="hidden" name="selected_date" 
                    value="<?php echo $_GET['selected_date'];?>">
                
                <?php echo $time?>&nbsp;&nbsp;&nbsp;
                </label>
                <?php ?>
    <?
        
    }

    }
    ?>
    I would like to display 'screening time' in next page,unfortunately by writing that line error arise.

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok.

    PHP Code:
    $name $_GET[time];
    var_dump($name); 
    or, if this works:
    PHP Code:
    $name $_GET[time[$rows['name']]]; 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So weird.when I do $time=var_dump($name),

    Movie Title Array
    Showtime

    And in the top of page shown:
    array(1) { ["White Noise 2: The Light"]=> string(7) "7 :30pm" },the selected movie title and screening time.

    When doesn't assign it to other,I get these thing,how can both field reflected to its actual value?

    Movie Title Array
    Showtime array(1) { ["White Noise 2: The Light"]=> string(7) "7:30pm " }

  6. #6
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post

    or, if this works:
    PHP Code:
    $name $_GET[time[$rows['name']]]; 
    same error occurs again

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Does the script know which movie it's asking for? The input field is storing itself in an array called time[] (because of it's name). Therefore it's stored as a php array, which has a key of the movie name, and a value of the chosen time.

    A quick solution would be to put
    PHP Code:
     $name $_GET[time][0]; 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya.the script know which movie is asking for but not displayed to the actual name because of the time array,however if I apply

    PHP Code:
    $name $_GET[time][0]; 
    var_dump($name); 
    time displayed as NULL,however name is blank

  9. #9
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    hmm....

    so if the script knows what the name is, could you just put
    PHP Code:
    $time $_GET['time'][$name]; 
    saying that $name is the actual name of the movie?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #10
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't proceed.Both name and time become blank.How about var_dump() what is it for?

  11. #11
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    var_dump() outputs the details of a variable to the browser, so you can see what it's value is, hence the text at the top of the window before.

    Can I see a bit more of the code please?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  12. #12
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    if (isset($_SESSION['gmemberid'])) {

        
    $tbl_name "movie";
        
    $result mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s
                 LIMIT 7'
    $tbl_name)) or die('Cannot execute query.');


        
    //$numrow = mysql_num_rows($result);


        
    while ($rows mysql_fetch_assoc($result)) {
            echo 
    '<table width="100%" border="0"><tr><td height="68">
                      <table width="100%" height="47" border="0">
                       ---------------------------------------------------------------------------------------------------------<br>'
    ;

            echo 
    '<strong>' $rows['name'] . ' (' $rows['classification'] . ')
                     <br></strong>'
    ;
            foreach (
    explode(','$rows['screeningTime']) as $time) { ?>
                <label>
                <input type="radio"  name="time[<?php echo $rows['name']; ?>]"
                  title ="screening time" value="<?php echo $time?>">
                 <input type="hidden" name="selected_date" 
                    value="<?php echo $_GET['selected_date'];?>">
                
                <?php echo $time?>&nbsp;&nbsp;&nbsp;
                </label>
                <?php ?>
    <?
        
    }

    }
    ?>
    selected_date is derived from previous page,so I put it as hidden field because it will pass to next page along with name and time.

    The output page,
    Code:
    $time = $_GET['time'][$name];
    
    <td width="18%"><strong>Movie Title</strong></td>
    <td width="82%"><?php echo $name?>
    <td><strong>Showtime</strong></td>
    <td><?php echo $time;?></td>
    <td><strong>Date</strong></td>
     <td><?php echo$_GET['selected_date'];?>
    I also have a javscript to test for null selection.
    Code:
    <script language="JavaScript" type="text/JavaScript">
        function validate(which) {
            var selects = which.getElementsByTagName('select');
            var radios = which.getElementsByTagName('input');
            for(sel = 0; sel < selects.length; sel++) {
                if(selects[sel].options[selects[sel].selectedIndex].text == 'Select') {
                    alert('Please select number of ticket!');
                    return false;
                }
            }
    
            var rselCount = 0;
            for(radio = 0; radio < radios.length; radio++) {
                if(radios[radio].checked) {
                  rselCount++;
                }
            }
    
            if(rselCount == 0) {
               alert('Please select screening time!');
               return false;
            }
            return true;
        }
        
            
    </script>

  13. #13
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    hmm...
    try this then:
    PHP Code:
    <?
    foreach($_GET['time'] as $key=>$value){
        
    $name $key;
        
    $time $value;
    }
    ?>
    <td width="18%"><strong>Movie Title</strong></td>
    <td width="82%"><?php echo $name?>
    <td><strong>Showtime</strong></td>
    <td><?php echo $time?></td>
    <td><strong>Date</strong></td>
    <td><?php echo $_GET['selected_date']; ?></td>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  14. #14
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by devil_vin View Post
    Hi..guys! what wrong with the code?
    PHP Code:
    $name = $_GET[time[<?php echo $rows['name']]];
    It indicated that Unexpected "[" expected "]" syntax error.
    $name = $_GET[$time[$rows['name']]];

    OR..

    $name = $_GET['time'.$rows['name']];

    One of those two should be what you're looking for.

  15. #15
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    no - the problem is that it's on a different page, so it doesn't know what the value for $rows['name'] should be.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  16. #16
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Finally done !You are great,arkinstall.Thank you very much for your initiative


    Quote Originally Posted by arkinstall View Post
    hmm...
    try this then:
    PHP Code:
    <?
    foreach($_GET['time'] as $key=>$value){
        
    $name $key;
        
    $time $value;
    }
    ?>
    <td width="18%"><strong>Movie Title</strong></td>
    <td width="82%"><?php echo $name?>
    <td><strong>Showtime</strong></td>
    <td><?php echo $time?></td>
    <td><strong>Date</strong></td>
    <td><?php echo $_GET['selected_date']; ?></td>


Bookmarks

Posting Permissions

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