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

Thread: php/mysql form

  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php/mysql form

    I have created a mysql databse with one master table with several slave tables. Now I created an update table that updates the master and all slave tables. The update table received the form variable (studentid) from a page where I select the student from another form. Now it is the form on the other page that passes studentid onto the update page that I am having issues with. I am in the process of learning php/mysql but need to get this working alot faster than I will be done the courses.

    I need the form to have a pull down menu that lists the last, middle, and first name of the student. Then the form passes the studentid of the that student on to the update page. Now the last, middle, and first name are in three different columns in the database. I am not sure how to create this form at all. Detailed help is appreciated.

    Darren

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Can you provide us with your database schema? I am confused by how you are explaining the setup for it.
    If I read this correct, you are saying you have a database table, with at least three different columns, Firstname, Lastname, and Middlename. I would also assume you have an Id (studentid) which is an autoincrementing number. As I understand it, you want to create a select menu listing all students names is that correct? I'm not certain if this is accurate, let alone how your update pages work, but thats not the issue right now.
    To create a list of all fields, do a query for all fields:
    PHP Code:
    $query mysql_query("SELECT `studentid`, `firstname`, `middlename`, lastname FROM `students` ORDER BY lastname ASC");
    if (
    mysql_num_rows($query) > 0)
    {
         echo 
    "<select name=\"selectname\">\n";
         while (
    $rows mysql_fetch_assoc($query))
         {
              echo 
    "<option value=\"" $rows['studentid'] . "\">" $rows['lastname'] . ", " $rows['firstname'] . " " $rows['middlename'] . "</option>\n";
         }
         echo 
    "</select>";

    You can also select rows based on certain criteria, studentid for example, by putting that into the query using a WHERE clause. You can generate the data required for this using a request method: $_GET, $_POST, $_REQUEST, $_COOKIE, $_SESSION, etc, but you need to know how to clean these variables so as to prevent sql-injections.
    Another thing to watch for is your number of rows, be kind to the users browser. The longer the select list (or generally more select lists will cause problems), the more likely the browser will become unstable. To counteract this, I would recommend instead setting a alphabetical listing, where the user selects what letter the last name starts with and querying the database using a LIKE clause.
    Is this along the idea you are looking for? If it is, I can give you more help with it. If not, can you explain a little more indepth what it is you are looking for?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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