Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 15th, 2005, 10:48 AM   #1
vidar
Newbie
 
Join Date: Mar 2005
Posts: 3
Rep Power: 0 vidar is on a distinguished road
Returning an array value

New to PHP and just learning. Old hack at programming, but this is new.

I'm trying to return an array of data from an SQL database. Here, I'll just post the code snippets, might be easier to read than for me to explain it...

<?php
$conn = mysql_connect("localhost", "admin", "******");
mysql_select_db("users",$conn);
$sqlcheck = "SELECT * FROM user_db";
$result = mysql_query($sqlcheck, $conn) or die(mysql_error());

// create edituser function
// arguments are $userid
function edituser($userid,$newarray) {
    showuserform();
    echo '<BR><BR>';
    echo '<b>'.$newarray[address].'</b><br><br>'  ;
    echo '<FORM method="POST">';
    echo 'Name : <input type="text" name="name" value="'.$newarray[name].'">';
    echo '<BR>';
    echo 'Address : <input type="text" name="address">';
    echo '<BR>';
    echo 'City : <input type="text" name="city">';
    echo '<BR>';
    echo 'Province/State : <input type="text" name="province" size=2>';
    echo '<BR>';
    echo 'PostalCode/Zip : <input type="text" name="postalcode">';
    echo '<BR>';
    echo 'Country : <input type="text" name="country">';
    echo '<BR>';
    echo 'Password : <input type="password" name="password">';
    echo '<BR>';

}
// create the form that shows the users to edit
function showuserform() {
          echo '<FORM method="POST">';
          echo '<select name="userid">';
          while ($newarray = mysql_fetch_array($GLOBALS["result"])) {
              echo '<option value="'.$newarray[name].'">'.$newarray[name].'</option>';
          }
          echo '</select><BR>';
          echo '<input type=submit value="Edit User" name="submit">';
          return $newarray;
}

if ($_POST['submit']) {
    edituser($userid,$newarray);
    return;
    }
else {
    showuserform();
    }
?>

Does that make sense in my showuserform() function to return the $newarray so that it can be used in the edituser function? Should I set that as a global?
vidar is offline   Reply With Quote
Old Mar 15th, 2005, 11:05 AM   #2
vidar
Newbie
 
Join Date: Mar 2005
Posts: 3
Rep Power: 0 vidar is on a distinguished road
As a note, the two lines in the code :

echo '<b>'.$newarray[address].'</b><br><br>'  ;
    echo '<FORM method="POST">';
    echo 'Name : <input type="text" name="name" value="'.$newarray[name].'">';

are just for testing purposes to see if it worked. :-)
vidar is offline   Reply With Quote
Old Mar 15th, 2005, 11:36 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
your show user form is returning a value but as with programming you need a variable in the main function to store that variable as....


so declare an array in edit user function then

array = showuserform();

well thats what i think anyways i could be wrong.
Berto is offline   Reply With Quote
Old Mar 15th, 2005, 11:45 AM   #4
vidar
Newbie
 
Join Date: Mar 2005
Posts: 3
Rep Power: 0 vidar is on a distinguished road
My functions are actually written reversed. It does the showuserform function first, then when I select a user from it, I want it to execute the edituser function. so declaring an array variable in the edituser function, won't give me anything the first time through...

Perhaps declare it globally?
vidar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC