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
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    insert to database table from drop down

    Hi
    im really stuck on this
    my form uses 2 drop downs and an input field (date) to insert a value into a table on the database, the 2 dropdowns values are from 2 other tables, so my query is not working i think.
    I can insert into the database a date but it does not take the drop down values. I must be close as it almost works!!

    PHP Code:
    if(isset($select)&&$select!=""){
    $select=$_POST['select'];
    }
    //form bits....then

    select name="select">
    <option value="">--- Select LastName---</option>
    <?

    $list
    =mysql_query("select * from customer order by customerId asc");

    // Show records by while loop.
    while($row_list=mysql_fetch_assoc($list)){
    ?>
    <option value="<? echo $row_list['customerId']; ?><? if($row_list['customerId']==$select){ echo "selected"; } ?>><? echo $row_list['lastName']; ?></option>
    <?

    }
    ?>
    </select>

    //then there is another select like the first... a normal submit

    <input type="submit" name="Submit" value="Select" />
    //and the query

    $result = "INSERT into loan (customerId, videoID, date)
        VALUES('$row_list[customerId]','$row_list[videoId]','$_GET[date]')";

    //followed by
    $result = mysql_query("SELECT customerId, videoId, date FROM loan where customer.lastName='$select' && video.title='$select' ");
    //to try and get it displaying - but from different tables-EEK! complicated!!
    so does anyone know why its only inserting the date and not the other values, is it my query that needs work or something else?

  • #2
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this:
    Code:
    if(isset($_POST))
    {
    if(isset($select)&&$select!="")
    {
    $select=$_POST['select'];
    }
    }


  •  

    Posting Permissions

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