Jump to content

Feature that allows 'admin' to create a new 'member'


Recommended Posts

OK this may be a bit much to ask about in this forum, but I'll give it a shot.

The site is a membership site - members sign up and give themselves a username/password - and are automatically assigned a MemberID (auto-increment).

They can then purchase an 'ad' on the site.

Member info is held in one table, 'ad' info is held in a different table - and they are linked via the MemberID. Simple, right?

There's an Admin Interface for administering the site. This requires an admin login.

I need to have a feature that lets Admin users create a New Member and a 'Free' Ad.

So, one form would be used to create the Member data, then another form to enter the Ad data.

This first form for entering Member data contains an Insert Query to create the new record. When this form is 'submitted', the MemberID is created.

How would I grab this MemberID, open the Ad form and create a New Ad for this New Member based on the newly assigned MemberID?

Since the Admin must login to access this feature, I don't think sessions will work (since the Admin's username/pw is being held in a session).

(To complicate things further, this admin interface has an include file for the Navigation. So when I try to use header("location:xxx.php:) to open the Ad form, I get an error.)

[b]So I guess the first big hurdle is grabbing the MemberID that isn't created until the form is submitted - so I can create a new Ad that is linked to that MemberID.[/b]

Thanks for any help...

Out of curiousity, why use two forms? You could use one form, have it contain both the member information and the ad information, and have the script which parses the input query both, one after the other. After the first query, I'd sort the affected rows in descending order to get the last row changed, and grab the ID from that. Then just do the second query.
Good point, Vorotaev. I guess there are two reason why I chose to use two forms: 1) if it's one form, there will be something like 45 fields to fill out - which to me seems a bit unruly; and 2) I don't know how to do what you suggest:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]After the first query, I'd sort the affected rows in descending order to get the last row changed, and grab the ID from that.[/quote]

(How DO you sort the affected rows? How do you find the last row changed?)

Other than that...

:-)
The function mysql_fetch_array will give you an array which contains the last row affected by the query, with the elements of the array being the columns in the affected row. I was sure there was a function that returned more than just the last row affected, but this works for our purposes anyways.

In this case you don't need to sort the results at all. You could use ORDER BY column_name DESC in a query to point out that you want the column results sorted by descending order, however.

--EDIT--

Oh, yes. The problem. Quite right.

Perhaps you should pass the result data to the next form, and find out the ID using mysql_fetch_array on that page.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The function mysql_fetch_array will give you an array which contains the last row affected by the query [/quote]

I've just tried to do this, but obviously there's something missing from this code to give the last record affected:

[code]
$sql = "SELECT * FROM members";

$result = mysql_query($sql);

$user_array = mysql_fetch_array($result);

echo $user_array["first_name"];
echo $user_array["last_name"];
echo $user_array["email"];
[/code]

This returns the first record in the table.

How do I get the last record?

OK - DUHHH!!! I forgot the order by clause.

I can now get the last record - HUZZAH!

Thanks - I believe I can work with this...

Very much appreciated!
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.