PDA

View Full Version : Help with Signup Sheet



Dirt_Diver
01-16-2009, 04:00 PM
I am making a sign up sheet for an upcoming event and I need some help with it.

What I am trying to do is have a user fill out a form and submit it. On submit I want the name they entered (entry_username) to post to the table. However on page entry or refresh you would see the name listed in a cell at the bottom of the page.

I hacked up some codes from another signup sheet on my site but for some reason I can't get it to post to the database.
Also I do not know how to get the usernames to post to the table.


<?php
// Connects to your Database
include("dbconnect");

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['username']) {
die('Please make sure you tell me your username ');
}
if (!$_POST['entry_username']) {
die('Please make sure you add a username for a team to place them on. ');
}
if (!$_POST['team_request']) {
die('Whoops, I think you forgot to select a team name. Please go back and choose one. ');
}
if (!$_POST['understand']) {
die('Please make sure you have read and understood the rules of the Olympics. ');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['entry_username'] = addslashes($_POST['entry_username']);
}
$usercheck = $_POST['entry_username'];
$check = mysql_query("SELECT entry_username FROM signups WHERE entry_username = '$entry_username'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('We\'re sorry, but <strong><u>'.$_POST['entry_username'].'</u></stong> has already been placed on a team.');
}

$insert = "INSERT INTO signups (username, entry_username, team_request, history, count, understand)
VALUES ('','".$_POST['username']."', '".$_POST['entry_username']."', '".$_POST['team_request']."', '".$_POST['history']."', '".$_POST['count']."', '".$_POST['understand']."')";

$add_member = mysql_query($insert) or die(mysql_error());
?>

<center>
Thank you <strong>
<?php
echo $_POST['entry_username']
?></strong> was added to Team <strong><?php
echo $_POST['team_request']
?></strong></center>

<?php
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="110%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="3%" rowspan="12"><div align="center"></div>
<div align="center"></div></td>
<td width="47%" valign="top"><div align="left">* Your Username:
<br>
<input name="username" type="text" id="username">
</div></td>
<td width="9%" align="left" valign="middle"><div align="left"><img src="../images_site/arrow.gif" width="25" height="18"></div></td>
<td width="41%" align="left" valign="middle" class="fade_out_text"><div align="left" class="fade_out_text">Please enter &quot;YOUR&quot; dpc username so I know who you are.</div></td>
</tr>
<tr>
<td><div align="center">
<p>&nbsp;</p>
</div></td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle"><div align="center"></div></td>
</tr>
<tr>
<td>* DPCO Entry Username:<br>
<input name="entry_username" type="text" id="entry_username"></td>
<td align="left" valign="middle"><div align="left"><img src="../images_site/arrow.gif" width="25" height="18"></div></td>
<td align="left" valign="middle" class="fade_out_text">This area is for the username that is being added to the team. </td>
</tr>
<tr>
<td><p>&nbsp;</p>
</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td>* Requested Team :
<br>
<select name="team_request" id="team_request">
<option selected>Please pick a team</option>
<option value="Team_A">Team A</option>
<option value="Team_B">Team B</option>
<option value="Team_C">Team C</option>
<option value="Team_D">Team D</option>
<option value="Team_E">Team E</option>
<option value="Team_F">Team F</option>
<option value="Team_G">Team G</option>
<option value="Team_H">Team H</option>
<option value="Team_I">Team I</option>
<option value="Team_J">Team J</option>
<option value="Team_K">Team K</option>
<option value="Team_L">Team L</option>
<option value="Team_M">Team M</option>
<option value="Team_N">Team N</option>
<option value="Team_O">Team O</option>
<option value="Team_P">Team P</option>
</select></td>
<td align="left" valign="middle"><div align="left"><img src="../images_site/arrow.gif" width="25" height="18"></div></td>
<td align="left" valign="middle" class="fade_out_text">This area is for the team that you are requesting to be on. </td>
</tr>
<tr>
<td><p>&nbsp;</p>
</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td><p>DPCO History:<br>
<input name="history" type="radio" value="yes">
Yes<br>
<input name="history" type="radio" value="no">
No </p>
</td>
<td align="left" valign="middle"><div align="left"><img src="../images_site/arrow.gif" width="25" height="18"></div></td>
<td align="left" valign="middle" class="fade_out_text">Have you ever participated in the DPC Olympics before? </td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td><p>If yes how many times:<br>
<input name="count" type="radio" value="1">
1 time<br>
<input name="count" type="radio" value="2">
2 times<br>
<input name="count" type="radio" value="3">
3 times. </p>
</td>
<td align="left" valign="middle"><div align="left"><img src="../images_site/arrow.gif" width="25" height="18"></div></td>
<td align="left" valign="middle" class="fade_out_text">Please tell me how many times you have participated in the DPC Olympics. </td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td>*
<input name="understand" type="checkbox" id="understand" value="checkbox">
I have read the rules and I understand how
the scores will be calculated. I'm ready to play. <br>
<br>
<input type="submit" name="Submit" value="Submit">
<br></td>
<td align="left" valign="middle"><div align="left"><img src="../images_site/arrow.gif" width="25" height="18"></div></td>
<td align="left" valign="middle" class="fade_out_text">Please make sure that you understand how the scoring system works. </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="left" valign="middle"><div align="left"></div></td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
</table>
</form>

BTW here is a visual of the page.
http://www.treasureshackonline.com/dpc_s4_signups.php

Dirt_Diver
01-16-2009, 05:24 PM
Also I have created a new database and moved everything over to it. I now have 17 tables within this one db,

1 table is for signups and the other 16 for the actual teams:
Teams A - P

I would like the sign up to actually post to the signups table and also have the username go into the table when they select a team.

For example user 'Joe blow' is signing up and filling out the form. He askes to be on Team A and so in the signups table his (username, entry_username, team_request, history, count, understand) go there however I also need his name to go into table "Team A".

BUT I need to restrict each team to 8 members. So I need it to echo something like there are 8 spots open on Team A. Then as people sign up it will echo something like "there are 4 spots remaining on Team A", and when full, "Team A is full"

Dirt_Diver
01-16-2009, 07:10 PM
Okay I see it's a bit much but can someone help me work on it in sections?

How do I post to 2 different tables in the same database?

JasonDFR
01-16-2009, 08:57 PM
$q = "INSERT INTO `table`.... ";

if ( $r = mysql_query($q) ) {

$q = "INSERT INTO `another_table`.... ";

$r = mysql_query($q) or die();

} else {

// MYSQL ERROR

}


I was also thinking that it may be easier to use one table for this. You would need a user_name or user_id column and a team column. 17 tables is way too complicated for what you are doing.

If you are going to keep track of users for your site, you should have one table called 'users' and one table called 'user_info'. The 'users' table has at minimum the columns: u_id, u_name, pass_word. You could also have active and date_created, but keep this table as simple as possible. The other table you need is 'user_info' that has columns: u_id, first_name, last_name, birthday, sex, address, etc...

With this setup you can use an id number to identify your users and duplicate the u_id column into new tables as you add them. You should never be duplicating information in your database, other than the foreign keys to link tables to one another.

Good Luck,

Jason

Dirt_Diver
01-16-2009, 09:27 PM
I thought 17 was alot but here is what I am trying to do.

I want to track which people enter which team and then display that team by member names.

I already have a table set up with the following fields
signups - (Table name)
username,
entry_username,
team_request,
history,
count,
understand

But on the same page I want to only display those in a specific team.
I thought it might be easy to just display a full table then trying to have php find and display only Team A users out of 160 names.

Also how to I limit the number of entries into a database? I want to limit all 16 teams to only 8 players per team. Again I thought it would be easy to insert users into table "team A" in MySQL when they select Team A with in the php page.


In the database there are 16 teams
Tables are called A-O and their are 2 fields within each table
id,
entry_username,

JasonDFR
01-16-2009, 10:00 PM
To display your team members:


<?php

$q = "SELECT * FROM `tableA` ";
$r = mysql_query($q);

?>

<div id="teamA">

<?php

while ( $row = mysql_fetch_assoc($r) ) {
echo '<p class="team_member">' . $row['user_name'] . '</p>';
}

?>

</div>

You'll have to repeat the above for all 16 tables though, and that can't be the best way to do it.

You can count the number of rows in any given teams table to see how many people are on each team. If it is 7 or less, add one, else, the team is full.

If you use one table, which I think it better, you can use the SQL COUNT() function to count all users on each team. Something like:



$q = "SELECT 'team', COUNT(user_name) FROM `teams` GROUP BY 'team' ";
$r = mysql_query($q);

while ( $row = mysql_fetch_assoc($r) ) {

$row['count(user_name)'] // Number of team members
$row['team'] // Team Name

}



This is off the top of my head and I think there is likely a much more elegant way. Check out count() and GROUP BY for your queries.

If you use one table you could also select all, group by team, and then use a loop to output the whole db table into a html table.

Hopefully you'll get some more advice.

Your project is definitely going to teach you a lot though.

Good Luck,

Jason

Dirt_Diver
01-18-2009, 04:12 PM
okay changing things around a bit to try and make them easier. Just to get the table on the webspge to display the usernames of each team.

Here's what I'm looking at:

-database name is signups.
- columns in db are

>id
>entry_username
>TeamCap
>team_request
>SeasonCount
>terms
>timestamp

What I want to do is select only 8 usernames from the entry_username column but I only want to select those users where the team_matches what I tell it too.

For example I have 128 people in my db. I have 16 teams with 8 members per team.

in my table on my webpage I have a cell where I want to only display only those members in team A under the header "Team A".

However I only want to display the first 8 members so on top of displaying the members alphabetically I also want to display those members who signed up first.

Can someone give me a hand with this one? Kris was on the right track but now I have changed things around so it's like I'm starting all over again.

Here is the start of the table, What I would like to do is just copy whatever php code I have in one field to the others and just change the name of the team.


<table width="616" border="0">
<tr>
<td><div align="center">Australia</div></td>
<td><div align="center">Canada I </div></td>
<td><div align="center">Canada II </div></td>
<td><div align="center">Canada III </div></td>
</tr>
<tr>
<td><div align="center">
<?
$ShowTeam = "SELECT entry_username, team_request FROM signups WHERE team_request='Australia' ORDER BY entry_username DESC LIMIT 8";
mysql_query($ShowTeam) or die(mysql_error());
?>
</div></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

Please help