Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Posts posted by DeanWhitehouse

  1. No, not yet, found a bug

     

    this code

    	if(preg_match('/\[user=(.*?)\]/s', $code, $regs))
    	{
    		$sql = mysql_query("SELECT username FROM user_details WHERE username = '".mysql_real_escape_string($regs[1])."'");
    		$user = mysql_fetch_assoc($sql);
    
    		if(mysql_num_rows($sql) == 0)
    			$code = preg_replace("/\[user=(.*?)\]/s","\\1",$code);
    		else
    		{
    
    			$code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink(null,$user['username']),$code);
    		}
    	}	
    
    	if(preg_match('/\[user\](.*?)\[\/user\]/s', $code, $regs))
    	{
    	    $sql = mysql_query("SELECT username FROM user_details WHERE username = '".mysql_real_escape_string($regs[1])."'");
    		$user = mysql_fetch_assoc($sql);
    
    		if(mysql_num_rows($sql) == 0)
    			$code = preg_replace("/\[user\](.*?)\[\/user\]/s","\\1",$code);
    		else
    		{
    
    			$code = preg_replace("/\[user\](.*?)\[\/user\]/s",CreateUserLink(null,$user['username']),$code);
    		}
    	}	
    

     

    when i do

    [user]blade280891[/user]

    [user]protestthehero[/user]

     

    [user=blade280891]

    [user=protestthehero]

     

    It makes four links which is correct, but the second and last link is to the first one if that makes sense . SO the above prints

     

    Blade280891

    Blade280891

     

    Blade280891

    Blade280891

    Any ideas?

  2. Sorry , i tried to only show code which applied to keep it simple, but this code is inside one bigger function which is then inside another function.

     

    So here is the bbcode function

    <?php
    Removed 
    ?>
    

    The output i need is a link to the users profile, the function createuserlink will create a link to the profile based on username or userid.

     

    the function createuserlink has these arguments

    function CreateUserLink($userid = null,$username = null)

     

    if $userid is null then it creates one using $username

     

    Scrap all that, solved i just needed to change

    $code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink(null,"\\1",$code);

     

    to

     

    $code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink(null,$regs[1]),$code);

     

  3. Not working, i tried this

     

    	if(preg_match('/\[user=(.*?)\]/s', $code, $regs))
    	{
    	    $sql = mysql_query("SELECT id FROM user_details WHERE username = '".mysql_real_escape_string($regs[1])."'");
    
    		if(mysql_num_rows($sql) == 0)
    			$code = preg_replace("/\[user=(.*?)\]/s","\\1",$code);
    		else
    		{
    
    			$code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink("\\1"),$code);
    		}
    	}	
    

     

    The bit where the link should be is empty

  4. No that code is fine, the fact is that after debugging i found out that the sql query is returning 0 rows although if i do it myself it doesn't, this is because i believe all the other text in the $code var is being sent as well, not just the bit i need

  5. Never mind, but i have got this now

    	$code = preg_replace("/\[user=(.*?)\]/s","\\1",$code);
    
    	$sql = mysql_query("SELECT id FROM user_details WHERE username = '".mysql_real_escape_string($code)."'") or die(mysql_error());
    
    	if(mysql_num_rows($sql) == 0)
    		$code = $code;
    	else
    	{
    		$code = CreateUserLink($code);
    	}
    
    

     

    But it isn't creating the link :s

  6. Thats the solution i thought off but i am worried about speed issues as there could be a lot of users in the db.

     

    I was thinking that it would loop through each user name and check the text for that username and replace it, but i assume this can be very slow?

  7. Hi again

    i have a little coding problem, regarding regex, i want to write a code that is like bbcode but searches for user names in the content and replaces them with profile links, any idea how i can do this using regex??

     

    Is it possible with regex, or shall i use something like a loop with str replace

  8. Hiya,

    Long time since i have posted a coding problem, but here it goes.

     

    I have created this code to work out what a user can steal from another user, but it seems to allow the user to try and steal anything even if it is on the list of unstealable items, any ideas as to why?

     

    Does in_array return a different value than i thought?

    Code Snippet

    			function StealType($extort)
    			{
    				$car = mysql_query("SELECT id FROM user_cars WHERE user_id = '".$extort['id']."' AND up_for_sale = '0' ORDER BY RAND() LIMIT 1");
    
    				$cash = mysql_query("SELECT money FROM user_stats WHERE user_id = '".$extort['id']."' LIMIT 1");
    				$c_check = mysql_fetch_assoc($cash);
    
    				$bullets = mysql_query("SELECT bullets FROM user_stats WHERE user_id = '".$extort['id']."' LIMIT 1");
    				$b_check = mysql_fetch_assoc($bullets);
    
    				$Not = array();
    
    				if(mysql_num_rows($car) == 0)
    				{
    					$Not[] = 1;
    				}
    
    				if($c_check['money'] < 100)
    				{
    					$Not[] = 2;
    				}				
    
    				if($b_check['bullets'] == 0)
    				{
    					$Not[] = 3;
    				}
    
    				print_r($Not);
    
    				if(in_array(array(1,2,3),$Not))
    				{
    					echo "S1";
    					return false;
    				}
    				elseif(!in_array(array(1,2,3),$Not))
    				{
    					echo "S2";
    					return rand(1,3);
    				}
    				elseif(!in_array(array(1),$Not) && in_array(array(2,3),$Not))
    				{
    					echo "S3";
    					return 1;
    				}
    				elseif(!in_array(array(2),$Not) && in_array(array(1,3),$Not))
    				{
    					echo "S4";
    					return 2;
    				}
    				elseif(!in_array(array(3),$Not) && in_array(array(1,2),$Not))
    				{
    					echo "S5";
    					return 3;
    				}
    				elseif(!in_array(array(1,2),$Not) && in_array(array(3),$Not))
    				{
    					echo "S6";
    					return rand(1,2);
    				}
    				elseif(!in_array(array(1,3),$Not) && in_array(array(2),$Not))
    				{
    					echo "S7";
    					return 1;
    				}
    				elseif(!in_array(array(2,3),$Not) && in_array(array(1),$Not))
    				{
    					echo "S8";
    					return rand(2,3);
    				}
    			}
    
    			$steal = StealType($extort);
    			if($steal == false)
    			{
    				echo "Failed! This user has nothing!";
    			}
    			elseif($steal == 1)
    			{
    				echo "To come car";
    			}
    			elseif($steal == 2)
    			{
    				echo "To come cash";
    			}
    			elseif($steal == 3)
    			{
    				echo "To come bullets";
    			}
    			else
    				echo "Error! What the fuck?";
    

  9. @redarrow, whitespace problems occur with HTML whitespace not PHP whitespace.

     

    Also

    Ahh well...first of all, I notice that you're checking if the form has been submitted by using if(isset($_POST['submit'])) which I assume is the submit button. The only problem with this is that if you don't actually click the submit button, ie you just press enter, it is ignored.

     

    So yeah, are you sure the form is actually being submitted?

     

    And also, maybe try simply echoing the contents of your sessions, to see if they are actually set or not...?

     

    Are you serious ??

     

    Try it, using if(isset($_POST['submit_button'])) works if you press the button or if you press the enter key.

  10. No one here will want to copy your code, if we can help fix it we can most likely create it ourselves.

     

    Here is what the code might be like

     

    mail($_POST['email'],"Thanks","Thank you for signing up","From: myemail@mysite.com");

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.