Forum Moderators: coopster
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.";
}
?>
<?
$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.