Feature that allows 'admin' to create a new 'member'
Posted 09 April 2006 - 03:08 PM
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.)
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.
Thanks for any help...
Posted 09 April 2006 - 04:33 PM
Posted 09 April 2006 - 04:43 PM
[!--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...
Posted 09 April 2006 - 04:53 PM
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.
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.
Posted 10 April 2006 - 01:01 AM
I've just tried to do this, but obviously there's something missing from this code to give the last record affected:
$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"];
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!
Posted 10 April 2006 - 12:03 PM
Wanted to let you know with your help I was able to create this feature - it was a heck of a lot more complex than I thought it was going to be...but it now works!
(How do you put "Solved" in the title of the thread?)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users