Jump to content
MakeWebGames

Help with sending message to players at registration


CENilsen

Recommended Posts

This is so that when you register for a game and login you have a mail message waiting for you....kinda like a welcome to my game such and such.

KyleMassacre helped me by developing a npc modification.

 

//replace [npcs_id] with the actual id of the bot.
//column names may not match so make sure you check your column  names
$db->query("insert into messages (from, to, subject, message, time) values ([npcs id], $i, 'subject here','message content here', ".time().")");

 

This is what i changed:

 

//replace [npcs_id] with the actual id of the bot.
//column names may not match so make sure you check your column  names
$db->query("insert into messages (from, to, subject, message, time) values ([2], $i, 'Welcome!','Testing123', ".time().")");

 

The problem is I inserted the code which worked after a few tries haha but yet i get a error that says the db can not update the query when the user finishes registering. I might just be placing it wrong in the register.php file.

Any guidance would be appreciated :)

Link to comment
Share on other sites

$db->query("insert into messages (mail_from, mail_to, mail_time, mail_subject, mail_text) values (2, $i, ".time().", 'Welcome','Welcome to the game')");

 

Try that. You didnt have the column names and you had your mail_from as this: [2]. I dont think that is a valid int or constant.

Also I edited your subject (for the thread) since its really not a NPC problem

Edited by KyleMassacre
Link to comment
Share on other sites

it helps if you have your error reporting turned on. look around for your error_handler.php. I think there is something in there about displaying errors and you just set it to true or false.

edit:

found it. go to libs/basic_error_handler.php in your file manager and find where it says:

define('DEBUG', false);

and change the false to true. Then try to register again and see what happens

Edited by KyleMassacre
Link to comment
Share on other sites

I get this message:

A critical error has occurred, and page execution has stopped. Below are the details:

1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1388552208, 'Welcome','Welcome to the game')' at line 1

Action taken: Attempted to execute query: insert into messages (mail_from, mail_to, mail_time, mail_subject, mail_text) values (2, , 1388552208, 'Welcome','Welcome to the game')

Here is the code and where i inserted your block:

require_once('globals_nonauth.php');
//thx to http://www.phpit.net/code/valid-email/ for valid_email

function valid_email($email)
{
   return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email);
}
print
       <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$set['game_name']}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="{$set['jquery_location']}"></script>
<script type="text/javascript" src="js/register.js"></script>
<link href="css/register.css" type="text/css" rel="stylesheet" />
</head>
<body>
<center>
<table width="970" border="0" cellpadding="0" cellspacing="0" class="table2">
<tr>
<td class="lgrad"></td>
<td class="center"><img src="title.jpg" alt="Mccodes Version 2" /><br />
<!-- Begin Main Content -->
EOF;
$IP = str_replace(array('/', '\\', '\0'), '', $_SERVER['REMOTE_ADDR']);
if (file_exists('ipbans/' . $IP))
{
   die(
           "<span style='font-weight: bold; color:red;'>
           Your IP has been banned, there is no way around this.
           </span></body></html>");
}
$username =
       (isset($_POST['username'])
               && preg_match(
                       "/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i",
                       $_POST['username'])
               && ((strlen($_POST['username']) < 32)
                       && (strlen($_POST['username']) >= 3)))
               ? stripslashes($_POST['username']) : '';
if (!empty($username))
{
   if ($set['regcap_on'])
   {
       if (!$_SESSION['captcha'] || !isset($_POST['captcha'])
               || $_SESSION['captcha'] != $_POST['captcha'])
       {
           unset($_SESSION['captcha']);
           echo "Captcha Test Failed<br />
		> <a href='register.php'>Back</a>";
           register_footer();
       }
       unset($_SESSION['captcha']);
   }
   if (!isset($_POST['email']) || !valid_email(stripslashes($_POST['email'])))
   {
       echo "Sorry, the email is invalid.<br />
	> <a href='register.php'>Back</a>";
       register_footer();
   }
   // Check Gender
   if (!isset($_POST['gender'])
           || ($_POST['gender'] != 'Male' && $_POST['gender'] != 'Female'))
   {
       echo "Sorry, the gender is invalid.<br />
		> <a href='register.php'>Back</a>";
       register_footer();
   }
   $e_gender = $db->escape(stripslashes($_POST['gender']));
   $sm = 100;
   if (isset($_POST['promo']) && $_POST['promo'] == "Your Promo Code Here")
   {
       $sm += 100;
   }
   $e_username = $db->escape($username);
   $e_email = $db->escape(stripslashes($_POST['email']));
   $q =
           $db->query(
                   "SELECT COUNT(`userid`)
                    FROM `users`
                    WHERE `username` = '{$e_username}'
                    OR `login_name` = '{$e_username}'");
   $q2 =
           $db->query(
                   "SELECT COUNT(`userid`)
   				 FROM `users`
   				 WHERE `email` = '{$e_email}'");
   $u_check = $db->fetch_single($q);
   $e_check = $db->fetch_single($q2);
   $db->free_result($q);
   $db->free_result($q2);
   $base_pw =
           (isset($_POST['password']) && is_string($_POST['password']))
                   ? stripslashes($_POST['password']) : '';
   $check_pw =
           (isset($_POST['cpassword']) && is_string($_POST['cpassword']))
                   ? stripslashes($_POST['cpassword']) : '';
   if ($u_check > 0)
   {
       echo "Username already in use. Choose another.<br />
	> <a href='register.php'>Back</a>";
   }
   else if ($e_check > 0)
   {
       echo "E-Mail already in use. Choose another.<br />
	> <a href='register.php'>Back</a>";
   }
   else if (empty($base_pw) || empty($check_pw))
   {
       echo "You must specify your password and confirm it.<br />
	> <a href='register.php'>Back</a>";
   }
   else if ($base_pw != $check_pw)
   {
       echo "The passwords did not match, go back and try again.<br />
	> <a href='register.php'>Back</a>";
   }
   else
   {
       $_POST['ref'] =
               (isset($_POST['ref']) && is_numeric($_POST['ref']))
                       ? abs(intval($_POST['ref'])) : '';
       $IP = $db->escape($_SERVER['REMOTE_ADDR']);
       if ($_POST['ref'])
       {
           $q =
                   $db->query(
                           "SELECT `lastip`
                            FROM `users`
                            WHERE `userid` = {$_POST['ref']}");
           if ($db->num_rows($q) == 0)
           {
               $db->free_result($q);
               echo "Referrer does not exist.<br />
			> <a href='register.php'>Back</a>";
               register_footer();
           }
           $rem_IP = $db->fetch_single($q);
           $db->free_result($q);
           if ($rem_IP == $_SERVER['REMOTE_ADDR'])
           {
               echo "No creating referral multies.<br />
			> <a href='register.php'>Back</a>";
               register_footer();
           }
       }
       $salt = generate_pass_salt();
       $e_salt = $db->escape($salt);
       $encpsw = encode_password($base_pw, $salt);
       $e_encpsw = $db->escape($encpsw);
       $db->query("insert into messages (mail_from, mail_to, mail_time, mail_subject, mail_text) values (2, $i, ".time().", 'Welcome','Welcome to the game')");
       $db->query(
               "INSERT INTO `users`
                (`username`, `login_name`, `userpass`, `level`,
                `money`, `crystals`, `donatordays`, `user_level`,
                `energy`, `maxenergy`, `will`, `maxwill`, `brave`,
                `maxbrave`, `hp`, `maxhp`, `location`, `gender`,
                `signedup`, `email`, `bankmoney`, `lastip`,
                `lastip_signup`, `pass_salt`)
                VALUES('{$e_username}', '{$e_username}', '{$e_encpsw}', 1,
                $sm, 0, 0, 1, 12, 12, 100, 100, 5, 5, 100, 100, 1,
                '{$e_gender}', " . time()
                       . ",'{$e_email}', -1, '$IP',
                '$IP', '{$e_salt}')");
       $i = $db->insert_id();
       $db->query(
               "INSERT INTO `userstats`
       	     VALUES($i, 10, 10, 10, 10, 10)");

       if ($_POST['ref'])
       {
           $db->query(
                   "UPDATE `users`
                    SET `crystals` = `crystals` + 2
                    WHERE `userid` = {$_POST['ref']}");
           event_add($_POST['ref'],
                   "For referring $username to the game, you have earned 2 valuable crystals!",
                   $c);
           $e_rip = $db->escape($rem_IP);
           $db->query(
                   "INSERT INTO `referals`
                    VALUES(NULL, {$_POST['ref']}, $i, " . time()
                           . ", '{$e_rip}', '$IP')");
       }
       echo "You have signed up, enjoy the game.<br />
	> <a href='login.php'>Login</a>";
   }
}
else
{
   if ($set['regcap_on'])
   {
       $chars =
               "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?\\/%^";
       $len = strlen($chars);
       $_SESSION['captcha'] = "";
       for ($i = 0; $i < 6; $i++)
           $_SESSION['captcha'] .= $chars[rand(0, $len - 1)];
   }

   echo "<h3>{$set['game_name']} Registration</h3>";
   echo "<form action=register.php method=post>
           <table width='75%' class='table' cellspacing='1'>
               <tr>
                   <td width='30%'>Username</td>
                   <td width='40%'>
                   	<input type='text' name='username'
                   	 onkeyup='CheckUsername(this.value);' />
                   </td>
                   <td width='30%'><div id='usernameresult'></div></td>
               </tr>
               <tr>
                   <td>Password</td>
                   <td>
                   	<input type='password' id='pw1' name='password'
                   	 onkeyup='CheckPasswords(this.value);PasswordMatch();' />
                   </td>
                   <td><div id='passwordresult'></div></td>
               </tr>
               <tr>
                   <td>Confirm Password</td>
                   <td>
                   	<input type='password' name='cpassword' id='pw2'
                   	 onkeyup='PasswordMatch();' />
                   </td>
                   <td><div id='cpasswordresult'></div></td>
               </tr>
               <tr>
                   <td>Email</td>
                   <td>
                   	<input type='text' name='email'
                   	 onkeyup='CheckEmail(this.value);' />
                   </td>
                   <td><div id='emailresult'></div></td>
               </tr>
               <tr>
                   <td>Gender</td>
                   <td>
                   	<select name='gender' type='dropdown'>
                   	<option value='Male'>Male</option>
                   	<option value='Female'>Female</option>
                    	</select>
                    <td><div id='cpasswordresult'></div></td>
                   </td>
               </tr>
               <tr>
                   <td>Promo Code</td>
                   <td><input type='text' name='promo' /></td>
               <td><div id='cpasswordresult'></div></td>
               </tr>

               <input type='hidden' name='ref' value='";
   if (!isset($_GET['REF']))
   {
       $_GET['REF'] = 0;
   }
   $_GET['REF'] = abs((int) $_GET['REF']);
   if ($_GET['REF'])
   {
       print $_GET['REF'];
   }
   echo "' />";
   if ($set['regcap_on'])
   {
       echo "<tr>
			<td colspan='3'>
				<img src='captcha_verify.php?bgcolor=C3C3C3' /><br />
				<input type='text' name='captcha' />
			</td>
		  </tr>";
   }
   echo "
		<tr>
			<td colspan='3' align='center'>
				<input type='submit' value='Submit' />
			</td>
		</tr>
</table>
</form><br />
> <a href='login.php'>Go Back</a>";
}
register_footer();

function register_footer()
{
   print
           <<<OUT

</td>
<td class="rgrad"></td>
</tr>
<tr>
<td colspan="3">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td class="dgradl"> </td>
<td class="dgrad"> </td>
<td class="dgradr"> </td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
OUT;
   exit;
}
Edited by CENilsen
Link to comment
Share on other sites

ok, try taking it out of where you currently have it and add it to line 171 and ill explain why you have that error.

You were right about where you placed the code. If you noticed you have a blank in your query error in the mail_to spot. And that is because your $i variable that you tried placing in there hasn't been instantiated as of yet (line 167). That $i is the last row number that got inserted into the database via your insert into users table query which in turn gives you your new user's id

Link to comment
Share on other sites

This is what my table looks like:

CREATE TABLE `mail` (
 `mail_id` int(11) NOT NULL auto_increment,
 `mail_read` int(11) NOT NULL default '0',
 `mail_from` int(11) NOT NULL default '0',
 `mail_to` int(11) NOT NULL default '0',
 `mail_time` int(11) NOT NULL default '0',
 `mail_subject` varchar(255) NOT NULL default '',
 `mail_text` text NOT NULL,
 PRIMARY KEY  (`mail_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

This is what my database insert looks like:

 

$db->query("INSERT INTO mail VALUES ('','0','Owner ID',{$i},unix_timestamp(),'Subject','Message')");                                                                                              
}

 

Mine works perfectly for me. After reading Kyles post since I didn't sift through all of your code he is of course right about your error. Happy New Years.

Edited by Veramis
Link to comment
Share on other sites

WrathCity - Critical Error

A critical error has occurred, and page execution has stopped. Below are the details:

1146: Table 'test123.messages' doesn't exist

Action taken: Attempted to execute query: insert into messages (mail_from, mail_to, mail_time, mail_subject, mail_text) values (2, 11, 1388586681, 'Welcome','Welcome to the game')

Then i looked at it and notice the code says "messages" when it should say mail. So i changed it to mail and it works :)

Only problem i ran into though is that it doesn't show the user that he received the mail... rather then it just is inserted into his mailbox...... So it says Mailbox(0) even though he has the welcome letter in his box.

Edited by CENilsen
Link to comment
Share on other sites

WrathCity - Critical Error

A critical error has occurred, and page execution has stopped. Below are the details:

1146: Table 'clanuf_wrathcity.messages' doesn't exist

Action taken: Attempted to execute query: insert into messages (mail_from, mail_to, mail_time, mail_subject, mail_text) values (2, 11, 1388586681, 'Welcome','Welcome to the game')

Then i looked at it and notice the code says "messages" when it should say mail. So i changed it to mail and it works :)

Only problem i ran into though is that it doesn't show the user that he received the mail... rather then it just is inserted into his mailbox...... So it says Mailbox(0) even though he has the welcome letter in his box.

Sigh.

 

$db->query("UPDATE `users` SET `new_mail` = `new_mail` + 1 WHERE `userid` = {$i}");
Link to comment
Share on other sites

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.   Paste as plain text instead

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