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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts

    php and checkboxes

    I have a page that reads the firstname (fname) from mysql database and gives each name a checkbox. See below:

    PHP Code:
    <html>
    <body>
    <?php

    mysql_connect
    ("localhost""root""dinosaur") or die(mysql_error());

    mysql_select_db("info") or die(mysql_error());

    $query "SELECT fname FROM users"
         
    $result mysql_query($query) or die(mysql_error());
    ?>

    <form name=myForm action='Edit.php' method='post'>
    <?php
    while($row mysql_fetch_array($result)){

        echo 
    $row['fname']?> <input type="checkbox" name="<?php $row['fname']?>"><BR><?php
    }
    ?>

    <input type='submit' value='Confirm'></form>
    </body>
    </html>
    Is the syntax correct where I am naming the checkbox? are the quotes correct? Also on the page where I am calling a value the syntax isnt correct becasue I get the error:

    "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\xampp\htdocs\Login\tests\Edit.php on line 1"

    PHP Code:
    <?php $thename=$_POST["$row['fname']"]; 
    echo 
    $thename;
    ?>
    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You have to <?php echo $row['fname']; ?>; you just have <?php $row['fname'] ?>

    On the syntax $_POST["$row['fname']"], just skip the outer quotes-- quotes indicate "I am putting a literal string here", which you aren't doing-- you are putting a variable there. Use $_POST[$row['fname']] and it'll work fine.
    Last edited by Fumigator; 11-02-2006 at 02:44 PM.


  •  

    Posting Permissions

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