#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Form and looking up a value in another table


    I didn't know whether this belongs here or in PHP...here goes.

    I'm trying (in a form) to look up the value of a field in a complete table.
    Table 1
    types
    typeid
    type
    Table 2
    pets
    petid
    name
    etc
    typeid

    Typeid I want to appear as an option in the form, looking up the type table.

    Here's what I have so far:
    PHP Code:
    <form action="upload_pet.php" method="POST" enctype="multipart/form-data">


    <br />Please add pet name: <br />
    <input type="text" name="name" size="25" maxlength="30" value=""><br /><br />
    <br />
    <br />Please add pet description: <br />
    <input type="text" name="description" size="100" maxlength="30" value=""><br /><br />
    <br />
    <br />Please add pet size: <br />
    <input type="text" name="size" size="25" maxlength="30" value=""><br /><br />
    <br />
    <? php
    require ("dbcnx.php");

    $get=mysql_query("SELECT * FROM types");
    ?>


    <br />Please choose pet type: <br />
    <select name="types">
      <?php
                 
    while($row mysql_fetch_assoc($get)){?>
                    <option value = "<?php echo($row['types'])?>" ></option>
                    <?php ?>
     </select>
    <br />

    <input type="submit" value="Submit Form">
    </form>
    I had hoped it would show 1-Dog, 2-Cat ( a bit like Access does with a combo box), and allow me to insert the typeid into the field.

    The error is : Parse error: syntax error, unexpected T_REQUIRE in /home/a2049476/public_html/pets/form_pets.html on line 22 which is the "require ("dbcnx.php");"
    I Googled "T_REQUIRE " without any luck.

    Your advice would be appreciated.
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    T_REQUIRE means that the php engine found the require token - ie you used the require function.

    The error message tells you where you used it as well.

    The fact that it was unexpected suggests that you didn't properly complete the code that preceeds it (eg missing ; , ), } etc)

    EDIT

    for your reference, here is a list of parser tokens: http://www.php.net/manual/en/tokens.php
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    I think your error problem is your bad php tag "<? PHP"

    Can't have a space in there.

    As for your logic problem, you can't echo the name of the table, you need to echo the field names ie,
    PHP Code:
    $row['typeid'
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by jimmyg999
    I think your error problem is your bad php tag "<? PHP"

    Can't have a space in there.

    As for your logic problem, you can't echo the name of the table, you need to echo the field names ie,
    PHP Code:
    $row['typeid'
    Thanks jimmyg999, that certainly removed the errors that were being displayed.
    But, at the moment, the option box is empty, despite there 3 or 4 records in the types table.
    I still can't quite get my head around doing the Access combo box idea ( showing 1-dog, 2 -cat etc) and being able to add the the typeid into the pets table.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    You should have read up on the proper format of an option tag in your html guide.

    PHP Code:
    echo "<option value='".$row['typeid'].' - '.$row['type']."'>$row['typeid'].' - '.$row['type']."</option>"; 

IMN logo majestic logo threadwatch logo seochat tools logo