Jump to content

While Loop and combo box


Recommended Posts

Hello, i am trying to make a form where you can select a member from a combo box then you would be able to edit there details, using a while loop.

all that is happening is that it there is a empty combo box and the button

heres my code:

[code]
<?php
    include("connection.inc.php");
    $connection = connect();

    $sql = "SELECT membership_no, forename, surname, address_1, address_2, post_code, telephone_no
                FROM tbl_members
                ORDER BY surname";

    $result = @mysql_query($sql) or die (mysql_error());
    $option_block = "";
    
    while ($row = mysql_fetch_array($result))
    {
                    $membership_no = $row['membership_no'];
        $forename = $row['forename'];
                    $surname = $row['surname'];
        $address_1 = $row['address_1'];
        $address_2 = $row['address_2'];
        $postcode = $row['post_code'];
        $telephone_no = $row['telephone_no'];
    
        $option_block .= "<option value=\"$membership_no\"> $membership_no, $forename, $surname, $address_1, $address_2, $post_code, $telephone_no</option>";
    }

    $display_block = "

        <FORM METHOD=\"post\" ACTION=\"index.php?page=show_existing.php\">

        <P><strong>Contact:</strong>
        <select name=\"membership_no\">
                $option_block
        </select>

        <INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"Select this Member\"></P>
        </form>

        ";
?>
<HTML>
<HEAD>
<TITLE>User Management</TITLE>
</HEAD>
<BODY>
<h1>User Management</h1>
<h3>Modify a User</h3>
<P>Select a user from the list below, to modify the user's record.</p>

<? echo "$display_block"; ?>

</BODY>
</HTML>
[/code]

Thanks to anyone that can help

Malcolm
Link to comment
Share on other sites

Hello

the code seems the be correct....

try removing the @ sign from mysql_query()

also try,

$result = @mysql_query($sql) or die (mysql_error());

$num = mysql_num_rows($result);
echo $num;//this will display no of records..if there are any in the db

hth
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.