Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 Bhaal

Bhaal
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 09 April 2006 - 03:08 PM

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.)

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...



#2 Vorotaev

Vorotaev
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationCanada

Posted 09 April 2006 - 04:33 PM

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.

#3 Bhaal

Bhaal
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 09 April 2006 - 04:43 PM

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...

:-)

#4 Vorotaev

Vorotaev
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationCanada

Posted 09 April 2006 - 04:53 PM

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.

#5 Bhaal

Bhaal
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 10 April 2006 - 01:01 AM

[!--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:

$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!

#6 Bhaal

Bhaal
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 10 April 2006 - 12:03 PM

Hey Vorotaev,

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!

Thanks!

(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