help with PHP

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

help with PHP

Post 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
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
DeathStrike
Registered User
Posts: 2663
Joined: 29 Jul 2004, 02:00
Location: hidden deep in the depths of the underworld is my home.
Contact:

Re: help with PHP

Post 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";
Spoiler: (show)
Image
SIG by HMAN 8)
Member of The Pride Of Darkness
DeathStrike on Twitter
About me
Spoiler: (show)
Asus P5KPL-CM motherboard, 4 GIG RAM, Q6600 @ 2.88GHz (Thanks Anthro), GeForce 8600GT, Samsung 2333 23" + CRT 17" Monitors. 500GB + 1.5TB HDD, Compro TV tuner, 350 WATT PSU
-Prometheus-
Resident Drama Llama
Posts: 967
Joined: 05 Mar 2008, 02:00
Contact:

Re: help with PHP

Post by -Prometheus- »

........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
Last edited by -Prometheus- on 03 Apr 2011, 22:52, edited 1 time in total.
BBLounge - Broadband and Technology forum
Please like our facebook page
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

Re: help with PHP

Post by Ryan_Cooper »

thanks guys
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

Re: help with PHP

Post 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>
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: help with PHP

Post 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";
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

Re: help with PHP

Post 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.
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

Re: help with PHP

Post 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?
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: help with PHP

Post 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">
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

Re: help with PHP

Post 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
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
Post Reply