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 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2011
    Location
    In ze hard disk drive
    Posts
    39
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Unhappy Assigning field values from SQL queries

    So far I have a drop down box that shows a list of client names from the database... but I cant figure out how to make the clients name, email and password pop up to be changed.

    The admin area is made from one index and multiple includes using domain extensions, therefore clicking links reloads the same page but with a different include.

    This is what I am aiming for:
    1) admin needs to change clients stored data
    2) admin chooses client from drop down list
    3) on submission the selected clients data is shown in a form
    4) the admin can edit the data in the fields
    5) the admin submits this form, and the clients info is updated.

    I am stuck on step 3.

    Thanks for any help in advance! (I am still self teaching)

    I hope that makes sense, here's the code so far:

    PHP Code:
                <?php
                $conn 
    mysql_connect("localhost""root""");

    if (!
    $conn) {
        echo 
    "Unable to connect to DB: " mysql_error();
        exit;
    }
      
    if (!
    mysql_select_db("report")) {
        echo 
    "Unable to select report DB: " mysql_error();
        exit;
    }

    $sql = ("SELECT * FROM clients ORDER BY client DESC");

    $result mysql_query($sql);

    if (!
    $result) {
        echo 
    "Could not successfully run query ($sql) from DB: " mysql_error();
        exit;
    }



        if(isset(
    $_POST['goedit'])){

    include(
    "config.php");

    $client_name = ("SELECT client FROM clients WHERE client = '$client'");
    $client_email = ("SELECT email FROM clients WHERE client = '$client'");
    $client_password = ("SELECT password FROM clients WHERE client = '$client'");

    $result1 mysql_query($client_name);
    $result2 mysql_query($client_email);
    $result3 mysql_query($client_password);

    ?>
                <div class="primary">
                    <form action="" method="post" target="_self" id="registerform">

                        <div>
                        <p>Client creation form</p>
                        </div>
                        
                        <div>
                        <label>Client Name <span class="required">*</span></label>
                        <?php echo('<input name="client" type="text" id="client" value="'.$result1.'" />'); ?>
                        </div>
                        
                        <div>
                        <label>Primary Email Address <span class="required">*</span></label>
                        <?php echo('<input name="email" type="text" id="email" value="'.$result2.'" />'); ?>
                        </div>

                        <div>
                        <label>Primary Password <span class="required">*</span></label>
                        <?php echo('<input name="password" type="password" id="password"  value="'.$result3.'" />'); ?>
                        </div>

                        <div>
                        <input type="submit"  value="Update Client" class="button" name="register2" id="register2">
                        </div>


                    </form>
                        <a style="font-size: 25px;" href="?d=1">Cancel and return</a>
                </div>
    <?php
    ;}
    ?>       
          <html>
          <a style="font-size: 25px;" href="?d=1">Cancel and return</a><br /><br />
          <section id="register" class="clearfix">
          
                 <div class="primary">
                    <form action="" method="post" target="_self" id="registerform">

                        <div>
                        <p>Please select the client you wish to edit:</p>
                        </div>
                        
                        <div>
                        <label>Client Name<span class="required">*</span></label>
                        <?php
                        
    echo("<select name='client' id='client'>");
                        while (
    $row mysql_fetch_assoc($result)) {
                        echo(
    '<option>'.$row["client"].'</option>');
                        
    $client $row["client"];
                        }
                        echo(
    "</select>");
                        
    ?>
                        </div>
                        <div>
                        <input type="submit"  value="Edit Client" class="button" name="goedit" id="goedit">
                        </div>
                        </form>
                        <br />
    <a style="font-size: 25px;" href="?d=1">Cancel and return</a>
                </div>
            </section>
            </html>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    $client_name = ("SELECT client FROM clients WHERE client = '$client'");
    $client_email = ("SELECT email FROM clients WHERE client = '$client'");
    $client_password = ("SELECT password FROM clients WHERE client = '$client'");
    That should be something like
    PHP Code:
    $sql "SELECT client,email,password FROM clients WHERE client = '$client'");
    $result=mysql_query($sql) or die(mysqll_error()); 
    and then you need to fetch the values from the result set using a function like mysql_fetch_assoc() or similar.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    mike94 (01-10-2012)

  • #3
    New Coder
    Join Date
    Dec 2011
    Location
    In ze hard disk drive
    Posts
    39
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    That should be something like
    PHP Code:
    $sql "SELECT client,email,password FROM clients WHERE client = '$client'");
    $result=mysql_query($sql) or die(mysqll_error()); 
    and then you need to fetch the values from the result set using a function like mysql_fetch_assoc() or similar.
    Thank you for your reply.

    I genuinly knew this but I was then unsure how to seperate the client, email and password into seperate fields as values without having them assigned as seperate variables?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Did you see the examples in the link embedded in my above post?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Dec 2011
    Location
    In ze hard disk drive
    Posts
    39
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Did you see the examples in the link embedded in my above post?
    AHH sorry! Its like -5c here and ive been up 18 hours! haha no excuse...

    PHP Code:
    while ($row mysql_fetch_assoc($result)) {
        echo 
    $row["userid"];
        echo 
    $row["fullname"];
        echo 
    $row["userstatus"];

    Thank you

    P.S. I gave you your 2,000th thank HAHA

  • #6
    New Coder
    Join Date
    Dec 2011
    Location
    In ze hard disk drive
    Posts
    39
    Thanks
    9
    Thanked 0 Times in 0 Posts
    How can I get the $client from the first form (the client selection drop down box?)

    PHP Code:
    WHERE client '$client'"); 

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    First form? Please explain.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New Coder
    Join Date
    Dec 2011
    Location
    In ze hard disk drive
    Posts
    39
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    First form? Please explain.
    The first form is the drop down box to select the client to edit, then the second is the form that appears with the clients details ready for editing.


  •  

    Posting Permissions

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