Forum Moderators: coopster

Message Too Old, No Replies

A Type of Advanced Register Form

Help me stop tearing out my hair with this advanced register script

         

teamcoltra

5:05 am on May 1, 2009 (gmt 0)

10+ Year Member



Okay I have the basics of a script that I am putting together (which is basically a modified "Signup" script) which basically has a member of a game I play sign up to be a "buyer" or a "seller"... what I want to be able to do... is when a person signs up as a "buyer" if there is already someone who is ready to sell... it takes the oldest result and assigns them to each other and emails them both.

I don't know if this makes since at all... I will eventually be also modifying the register.php script to use GET from the URL to simply be integrated in other programs that are developed for the game.

I basically am wondering what I should be doing with my register script, since I figure my input form is fine... I am very lost past the point that I am at.
(sorry for quotes and not "code" but the "code" code was not working)

INPUT FORM


<table><tr>
<form action=register.php method=post>

<td width="81">Ruler:</td>
<td width="247"><input name="ruler" size="30" autocomplete="off" value="" type="text" /></td>

</tr><tr>

<td>Nation Name:</td>
<td><input name="nation" size="30" type="text" /></td>

</tr>

<tr>

<td>Email</td>
<td><input name="email" size="30" type="text" /></td>

<td>Nation Link</td>
<td><input name="link" size="30" type="text" /></td>

<td>Email</td>
<td><input name="email" size="30" type="text" /></td>

<td>Buy/Sell</td>
<td>
<select name="choice">
<option value="Buyer">Jr.High</option>
<option value="Seller">HighSchool</option>
</select>
</td>

</tr>
</table>

REGISTER.PHP


<?php
include 'mysql-connect.php';
$username = $_POST['ruler'];
$username = $_POST['nation'];
$link = $_POST['link'];
$email = $_POST['email'];
$choice = $_POST['choice'];
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];

$result = mysql_num_rows(mysql_query("SELECT * FROM users WHERE choice='sell'"));
if($result == 1)
{
mail('caffeinated@example.com', 'My Subject', $message);
echo "Congratulations there was a seller available! Their nation link is ".$link." and you have been assigned to them"
}
else
{
mysql_query("INSERT INTO users (username, nation, link, choice, email, timestamp, ip)
VALUES ('$username', '$nation', '$link', '$userid', '$userlevel', '$choice', '$email', '$time', '$ip')");
echo "Success! You may now login as normal.";
}
?>

midtempo

12:55 pm on May 1, 2009 (gmt 0)

10+ Year Member



register.php

<?
$inputs = array('ruler', 'nation', 'link', 'email', 'choice');
foreach ($inputs as $item) {
$$item = addslashes(strip_tags($_POST['item']));
}
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];

// add them to the db - note: user table MUST have an autoincrement user_id
$result = mysql_query("insert into users (username, nation, link, choice, email, timestamp, ip) values ('$ruler', '$nation', '$link', '$email', '$choice', '$time', '$ip')");

// and get the user id
$user_id = mysql_insert_id();

// now you need a table that matches one to t'other
// this table should contain: match_id, seller_id, buyer_id

switch ($choice) {
case 'Seller':
// looking for a buyer who is NOT already in the match table
$sql = mysql_query("select u.* from user u left join match m on u.user_id = m.buyer_id where m.match_id is NULL and u.choice = 'Buyer' order by u.user_id limit 1");
if (mysql_num_rows($sql)) {
// there's a match, get row, grab buyer id, insert buyer_id, user_id (as seller_id) into match table. send emails.
// do that here.

break;

default: // must be buyer
// do same as above, but use m.seller_id and u.choice = 'Buyer'
}

NOTE: i've just hammered this out here - not tested, not checked, no promises it'll work.