Results 1 to 8 of 8

Thread: Problem with code

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Problem with code

    I have problem with this code
    I want to select Character Select Points and to add in table

    T_MasterLevelSystem > ML_POINT
    the points i selected in "Select Points"

    here is the html code:
    Code:
    {if count($message.messages) > 0}
    	{foreach item=text from=$message.messages}
    		<div class="{$message.type}">{$text}</div>
    	{/foreach}
    {/if}
    <form method="POST" action="">
    <table width="100%" align="center">
    	<tr>
    		<td>SELECT CHARACTER:</td>
    		<td> 
    			<select name="char">
    				<option disabled="disabled" selected="selected" value="">SELECT</option>
    				{foreach item=char from=$chars}
    					<option value="{$char.id}">{$char.name}</option>
    				{/foreach}
    		    </select>
    		</td>
    		<td>SELECT Points:</td> 
    		<td>
    			<select name="lvl">
    				<option disabled="disabled" selected="selected" value="">SELECT</option>
    				{$form}
    			</select>
    		</td>
    		<td rowspan="2"><input type="submit" value="submit" name="edit_level"></td>
    	</tr>	
    </table>	
    </form>
    Here is the php file :
    Code:
    <?php
    
    	if(!defined('DmNMuSite'))
    		die('Go away!');
    
    	$templatefile		= 'site_login.html';
    
    	if($auth->AnalyseFingerPrint() && $auth->isLoggedIn() && !$auth->isBanned()){
    		$errors = array();
    		$templatefile		= 'buymasterpoints.html';
    		$get_chars =  $db->Query('SELECT '.CHARID.', Name FROM Character WHERE AccountId = \''.$_SESSION['name'].'\'', MUONLINE);
    		if($get_chars != false){
    			if($db->numrows($get_chars)){
    				$chars = array();
    				while($row = $db->fetch($get_chars)){
    					$chars[] = array('id'	=> (int)$row[CHARID],
    									 'name'	=> htmlspecialchars($row['Name']));
    				}
    				$oSmarty->assign('chars',	$chars);
    			}
    			else{
    				$oSmarty->assign('error',       'You don\'t have characters on your account');
    			}
    		}
    		else{
    			$error	= true;
    			$oSmarty->assign('error',       htmlspecialchars($db->errormsg()));
    		}
    
            $points = ($config['buymlevel']['type'] == 1) ? 'credits' : 'gold credits';
            $form 	= '';
    
            foreach($config['buymlevel']['level'] as $level => $price){
                $form .= '<option value="'.$level.'">'.$level.' points price '.$price.' '.$points.'</option>';
            }
    		$oSmarty->assign('form', $form);
    
    		if(isset($_POST['edit_level'])){
    			$char 	= isset($_POST['char']) ? ctype_digit($_POST['char']) ? (int)$_POST['char'] : '' : '';
    			$level 	= isset($_POST['lvl']) ? ctype_digit($_POST['lvl']) ? (int)$_POST['lvl'] : '' : '';
    			if($char == '')
    				$errors[] = 'Please select character.';
    			if($level == '')
    				$errors[] = 'Please select level.';
    			if(!array_key_exists($level, $config['buymlevel']['level']))
    				$errors[] = 'Invalid level selected';
    			if (count($errors) > 0){
    				$oSmarty->assign('message',		array('type'		=> 'error',
    													  'messages'	=> $errors));
    			}
    			else{
    				//$check_char = $db->Query('SELECT clevel FROM Character WHERE '.CHARID.' = '.$char.' AND AccountID = \''.$_SESSION['name'].'\'', MUONLINE);
    				$check_charx = $db->Query('SELECT ML_POINT FROM T_MasterLevelSystem WHERE CHAR_NAME = '.$char.'', MUONLINE);
    				if($check_charx != false){
    					if($db->numrows($check_charx)){
    						$chars 		= $db->fetch($check_charx);
    						$real_level = $level+$chars['ML_POINT'];
    						$credits 	= check_points($_SESSION['name'], $config['buymlevel']['type']);
    						$new_level 	= ($real_level > $config['buymlevel']['maxlevel']) ? $config['buymlevel']['maxlevel'] : $real_level;
    						$price		= $config['buymlevel']['level'][$level];
    						
    						if($credits < $price){
    							$oSmarty->assign('message',		array('type'		=> 'error',
    													              'messages'	=> 'You dont have enough credits'));
    						}
    						else{
    							$update_char = $db->Query('UPDATE T_MasterLevelSystem SET ML_POINT = '.$new_level.' WHERE CHAR_NAME = '.$char.'', MUONLINE);
    							if($update_char != false){
    								$remove_cred =  $db->Query('exec Add_Credits \''.$_SESSION['name'].'\', '.(int)$price.', '.$config['buymlevel']['type'].', 2', MUONLINE);
    								if($remove_cred != false){
    									$oSmarty->assign('message',		array('type'		=> 'true',
    																		  'messages'	=> 'Character Master Points Successfully Updated'));
    									 writelog(''.$char[CHARID].' Character Master Points Successfully Updated To '.$new_level.'','buylevel');
    								}
    								else{
    									$error	= true;
    									$oSmarty->assign('error',       htmlspecialchars($db->errormsg()));
    								}
    							}
    							else{
    								$error	= true;
    								$oSmarty->assign('error',       htmlspecialchars($db->errormsg()));
    							}
    						}
    					}
    					else{
    						$oSmarty->assign('message',		array('type'		=> 'error',
    															  'messages'	=> 'Character Not Found'));
    					}
    				}
    				else{
    					$error	= true;
    					$oSmarty->assign('error',       htmlspecialchars($db->errormsg()));
    				}
    			}
    		}
    	}
    	else{
    		if(!$auth->AnalyseFingerPrint()){
    			$oSmarty->assign('message',			array('type'		=> 'error',
    							                          'messages'	=> 'Wrong session.'));
    		}
    		if(!$auth->isLoggedIn()){
    			$oSmarty->assign('message',			array('type'		=> 'error',
    								                      'messages'	=> 'You are not logged in. Please login.'));
    		}
    		if($auth->isBanned()){
    			$oSmarty->assign('message',			array('type'		=> 'error',
    			                                          'messages'	=> 'Your account has been banned.'));
    		}
    	}
    
    	if (!$error)
    		$oSmarty->display('file:pages/account/'.$templatefile);
    
    ?>
    And i Get Error : Syntax error converting the varchar value 'Th3AnGeL' to a column of data type int.
    Why it reads Character Name, and wants to put it as int ?
    I want to put in column ML_POINTS = (Select Points) where CHAR_NAME = (Select Character) in table > T_MasterLevelSystem

    can someone help here

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Problem with code

    You're selecting CHARID (actually you're selecting a string literal which is defined by the variable CHARID, but I don't even see where it gets set)... which I'm guessing is Th3AnGeL ... which means its a string... but you try to stuff it into an INT ...
    Code:
    $chars[] = array('id'	=> (int)$row[CHARID],
    On that note... It maybe helpful in the future to point out the line that's giving the error... However, the error isn't happening where you think it is... it's actually happening long before that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Problem with code

    i try alot of stuff even without array but cant manage to do it
    about CHARID it reads > mu_id
    but in table T_Master , there is no mu_id only columns CHAR_NAME,ML_POINTS

    can someone help me build this php complate

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Problem with code

    T_Master isn't the problem... that's what I was trying to say... you're problem, I think happens very early in the code....
    Code:
    <?php
    
    	if(!defined('DmNMuSite'))
    		die('Go away!');
    
    	$templatefile		= 'site_login.html';
    
    	if($auth->AnalyseFingerPrint() && $auth->isLoggedIn() && !$auth->isBanned()){
    		$errors = array();
    		$templatefile		= 'buymasterpoints.html';
    		$get_chars =  $db->Query('SELECT '.CHARID.', Name FROM Character WHERE AccountId = \''.$_SESSION['name'].'\'', MUONLINE);
    		if($get_chars != false){
    			if($db->numrows($get_chars)){
    				$chars = array();
    				while($row = $db->fetch($get_chars)){
    					$chars[] = array('id'	=> (int)$row[CHARID],
    									 'name'	=> htmlspecialchars($row['Name']));
    The first part in red... that returns a string literal of what ever is in CHARID ... but in the second highlighted line,you're trying to make it an integer... string "Th3AnGeL" can't be converted to an integer... That's what I'm saying... I think your error happens a lot sooner in the code than you think it does. But I'm guessing here. it's hard to read the code, it feels all over the place, and the formatting the site does to the code boxes doesn't help.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Problem with code

    here i upload original file name buylevel that is similar with what i want to do
    can you convert it to update the table T_MasterLevelSystem SET ML_POINT = 'Selected Points' WHERE CHAR_NAME = 'Selected Char'

    in table T_MasterLevelSystem info is (there it doest has mu_id):
    http://gyazo.com/1faa7eaaf1f0d2d0a26ec1dca1032bb6
    Attached Files Attached Files

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Problem with code

    someone can convert it ?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Problem with code

    some help?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Problem with code

    maybe nobody can recode it to work ;[

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width