Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-10-2012, 12:57 PM   PM User | #1
mike94
New Coder

 
Join Date: Dec 2011
Location: In ze hard disk drive
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
mike94 is an unknown quantity at this point
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>
mike94 is offline   Reply With Quote
Old 01-10-2012, 01:06 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
$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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
mike94 (01-10-2012)
Old 01-10-2012, 01:12 PM   PM User | #3
mike94
New Coder

 
Join Date: Dec 2011
Location: In ze hard disk drive
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
mike94 is an unknown quantity at this point
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?
mike94 is offline   Reply With Quote
Old 01-10-2012, 01:18 PM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Did you see the examples in the link embedded in my above post?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-10-2012, 01:20 PM   PM User | #5
mike94
New Coder

 
Join Date: Dec 2011
Location: In ze hard disk drive
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
mike94 is an unknown quantity at this point
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
mike94 is offline   Reply With Quote
Old 01-10-2012, 01:25 PM   PM User | #6
mike94
New Coder

 
Join Date: Dec 2011
Location: In ze hard disk drive
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
mike94 is an unknown quantity at this point
How can I get the $client from the first form (the client selection drop down box?)

PHP Code:
WHERE client '$client'"); 
mike94 is offline   Reply With Quote
Old 01-10-2012, 01:30 PM   PM User | #7
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
First form? Please explain.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-10-2012, 03:48 PM   PM User | #8
mike94
New Coder

 
Join Date: Dec 2011
Location: In ze hard disk drive
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
mike94 is an unknown quantity at this point
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.
mike94 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:59 PM.


Advertisement
Log in to turn off these ads.