Jump to content

PHP & MySQL help!


ukrnaut

Recommended Posts

Hi all,

 

I'm more or less a PHP/Database newbie and I'm having some problems with code. I'm making a user login/members area for a client. The user registers for an account and when they login to the members area, they're able to create a team to enter a competition.

 

The user login is working fine as far as I can tell. I found some tutorials online and was able to get it working. I'm having problems with the team registration part, however.

 

My problem is this: the team registration goes through 4 pages (or steps first step is register a team name, second is to register a primary contact, third is secondary contact, last is general team information). My database is working in such a way that I have a table for team, primary contact, secondary contact and team information. What I need help with is when they enter a primary contact, I can't get it to link to that specific team. I have the tables linked fine with foreign keys and I think I'm doing that right (the foreign key for primary contact, secondary contact and team information is teamID).

 

My understanding is I need to run a query to determine the teamID and then put the result of that query into my insert for primary, secondary and team info. I'm just unsure how to run the query and store the output into a variable.

 

Here's what I have so far (only showing primary contact page):

 

$user = $_SESSION['SESS_MEMBER_ID'];

$qry = "SELECT teamID FROM dboat_team WHERE userID = $user";

mysql_query($qry);

if($qry) {
     if(mysql_num_rows($qry) == 1) {
          $results = mysql_fetch_assoc($qry);
          $theTeam = $results['teamID'];}
     }

//get values from previous page
$fName = "'" . $_POST['FirstName'] . "'";
$lName = "'" . $_POST['LastName'] . "'";
$Country = "'" . $_POST['Country'] . "'";
$Address = "'" . $_POST['Address'] . "'";
$City = "'" . $_POST['City'] . "'";
$Province = "'" . $_POST['provincestate'] . "'";
$postalcode = "'" . $_POST['postalZipCode'] . "'";
$email = "'" . $_POST['Email'] . "'";
$phonenum = "'" . $_POST['Phone'] . "'";
$phoneType = "'" . $_POST['phonetype'] . "'";

//run query to insert team
$goodJobQuery = "INSERT INTO dboat_pcontact VALUES(NULL, $fName, $lName, $Address, $City, $Province, $postalcode, $Country, $phonenum, $phoneType, $email, $theTeam)";

mysql_query($goodJobQuery);

 

The session is working, because if I echo out the userID on the page it gives me the proper one. I'm just unsure about how to do the rest. I'm sure it's a simple thing I'm just overlooking.

 

Any help is greatly appreciated. Sorry for my post but I'm really stuck and could use some help!

Link to comment
Share on other sites

You have a logic error if mysql_num_rows() returns something different then 1 the variable $theTeam does not exist and results in NULL and a warning (do you have error_reporting and display_errors set correctly in your php.ini?). The solution is to simple include all your code in the if (mysql_num_rows($result) === 1) block.

Link to comment
Share on other sites

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.