SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying result from a posted form

    I'm having trouble showing the outpup of the post variable. The only thing that showing on my confirm.php page is:

    For submit, the value is 'Submit Query'


    i'm looking to display the list of books and the quantity inserted in the input box.

    Any help would be appreciated.

    enter.php

    Code:
    $result = mysql_query("SELECT * FROM test");
    
    echo '<form action ="confirm.php" method="post">';
    
    echo'<p><table border = "1">';
    
    echo'<tr><td>Title</td><td>CD</td><td>Quantity</td></tr>';
    
    while($row = mysql_fetch_array($result)){
    	echo '<tr>';
    	echo '<td>'. $row['title'] .'</td>';
    	echo '<td>'. $row['cd'] .'</td>';
    	echo '<td><input type = "text" /></td>';
    	echo '</tr>';
    }
    
    echo'</table></p>';
    echo'<input name="submit" type="submit" />';
    echo'</form>';
    confirm.php

    Code:
    <?php
          foreach($_POST as $key => $value) {
            echo "<p>For " . $key . ", the value is '" . $value . "'.</p>";
          }
    ?>

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have no name= attribute for the input type="text" elements of the form. Try this:

    Code:
    echo '<td><input type="text" name="cd[]" /></td>';
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I get when I implement what you suggested:

    For cd, the value is 'Array'.

    For submit, the value is 'Submit Query'.


    Any other ideas on how I could get this working.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Good. I was expecting it to be an array.

    PHP Code:
    <?php
    foreach($_POST as $key => $value) {
        if (
    is_array($value)) {
            foreach (
    $value as $idx => $val) {
                echo 
    "<p>For " $key "[" $idx "], the value is '" $val "'.</p>";
            }
        } else {
            echo 
    "<p>For " $key ", the value is '" $value "'.</p>";
        }
    }
    ?>
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru View Post
    Good. I was expecting it to be an array.

    PHP Code:
    <?php
    foreach($_POST as $key => $value) {
        if (
    is_array($value)) {
            foreach (
    $value as $idx => $val) {
                echo 
    "<p>For " $key "[" $idx "], the value is '" $val "'.</p>";
            }
        } else {
            echo 
    "<p>For " $key ", the value is '" $value "'.</p>";
        }
    }
    ?>
    PHP Code:
    print_r($_POST); 

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Indeed. But I was expanding on the OP's original request. And for the output to be in a readable format this is needed ...

    PHP Code:
    <pre>
    <?php print_r ($_POST); ?>
    </pre>
    Ian Anderson
    www.siteguru.co.uk


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
  •