Page 1 of 1

help with PHP

Posted: 08 Dec 2010, 15:18
by Ryan_Cooper
Hi guys ...I'm fairly new to PhP and I'm still learning.

I'm trying to build a form that fist gives me a drop down box list of users in a db that I can then submit via POST to another form, but for some reason the names are not pulling into the drop down box.
this is what my code looks like so far:

Code: Select all

<?php
include('config.inc');

    $sql="SELECT user FROM member";
    $result = mysqli_query($sql);
    
    while ($row = mysqli_fetch_array($result))
    {
        $id = $row['fuser'];
        $item .= "<OPTION VALUE=\"$id\"></option>\n";
    }
?>
<body onload="document.edit_user.fuser.focus()">

    <form action="nuserform.php" name="edit_user" method="post" >
    
    User: <SELECT NAME="fuser">
        <option value=0>Choose
        <?php echo $item;?>
        </SELECT>
        
        <br />
        <input type="submit" value="Select User" target="userframe" /> 
        <input type="reset" Value ="Clear Fields">
    </form>
</body>
the file config.inc containsd my db connection strings which is then used in the variable $cxn (i hope i said that right)

any help would be greatly appreciated

Re: help with PHP

Posted: 08 Dec 2010, 15:22
by DeathStrike
Well your items won't display because you are only filling in the names in the Value fields?

Code: Select all

 $item .= "<OPTION VALUE=\"$id\"></option>\n";
should be

Code: Select all

 $item .= "<OPTION VALUE=\"$id\">TEXT YOU WANT DISPLAYED</option>\n";

Re: help with PHP

Posted: 10 Dec 2010, 00:02
by -Prometheus-
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................

Re: help with PHP

Posted: 10 Dec 2010, 09:20
by Ryan_Cooper
thanks guys

Re: help with PHP

Posted: 13 Dec 2010, 10:11
by Ryan_Cooper
ok guys I got it figured out and it supposed to have been this:

Code: Select all

<?php
include('config.inc');

    $sql="SELECT mem_id,user FROM members";
    $result = mysqli_query($cxn,$sql);
   
while ($row = mysqli_fetch_assoc($result))
{
  $mem_id = $row['mem_id'];
  $user = $row['user'];
  $item .= "<option value=$mem_id>$user\n";
}

?>
<body onload="document.edit_user.fuser.focus()">

    <form action="nuserform.php" name="edit_user" method="post">
   
    Select a User: <select name="mem_id">
        <option value=0>Choose
        <?php echo $item;?>
        </SELECT>
       
        <br />
        <input type="submit" value="Select User" target="userframe" />
        <input type="reset" Value ="Clear Fields">
    </form>
</body>

Re: help with PHP

Posted: 13 Dec 2010, 10:30
by RuadRauFlessa
You are causing a HTML error there. You have to close the option tags.
chage

Code: Select all

$item .= "<option value=$mem_id>$user\n";
to this

Code: Select all

$item .= "<option value=$mem_id>$user</option>\n";

Re: help with PHP

Posted: 13 Dec 2010, 14:07
by Ryan_Cooper
thanks RDF...I was wondering why even though it was displaying correctly it wasn't exactly pushing forward like i wanted it too.

Re: help with PHP

Posted: 14 Dec 2010, 09:37
by Ryan_Cooper
I have one more question...
How do I get the form that loads when you hit submit to load in a new frame and not in the same frame?

Re: help with PHP

Posted: 14 Dec 2010, 09:45
by RuadRauFlessa
change

Code: Select all

<form action="nuserform.php" name="edit_user" method="post">
to

Code: Select all

<form action="nuserform.php" name="edit_user" method="post" target="_blank">

Re: help with PHP

Posted: 14 Dec 2010, 10:27
by Ryan_Cooper
thanks ...I had that in once and it didnt work so I changed it back .....i guess I must not have reloaded the script or waited long enough for it to reload