Jump to content

Zephni

Members
  • Posts

    109
  • Joined

  • Last visited

Posts posted by Zephni

  1. Hi guys, I just decided to add an addition question in my site for submitting a form, not gonna say where coz one of you will most proberly try to prove it doesnt work! I have a feeling its easy enough for someone to send my form by getting the two variables and evaluating them. But how would they do that? and how would they know the names of the variables to send...?

     

    Is there a way of doing a math captcha that cannot be hacked?

  2. Hi guys, I have been using MSQL for quite some time, yet I still tend to use PHP to sort out some of my querys.. Which I know is wrong, I feel I need to understand the JOIN method a little more but can't quite get my head around it.

     

    Could someone explain this query I found on w3s in english:

     

    SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
    FROM Persons
    INNER JOIN Orders
    ON Persons.P_Id=Orders.P_Id
    ORDER BY Persons.LastName
    

     

    Thank you v much for you help

  3. I would say have it all in one table, I like everything in it's right place, but this also may depend on weather you know there will ONLY be 3 seperate tables, or weather you may at some point need to add more.

     

    I personaly would say it is good practise to keep it all in one table, who cares how many results are in a table, thats what they are for.

  4. Hello guys, I do hundreds of INSERT INTO's I work for a web development company and maybe I shouldn't coz' this is embarrassing. This is my INSERT:

     

      $query_add_refference = mysql_query("INSERT INTO references VALUES ('','$name','$value')")or die(mysql_error());
    

     

    The error I am getting is:

     

      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 'references VALUES ('','NameTest','ValueTest')' at line 1
    

     

    I cannot see the syntax error myself :s maybe its just been a long day at work :( anyone have any idea's? ALSO my biggest question is... Why is it saying the error is at line 1? The mysql query is on line 7 :s This happened to me once before.. Thank you very much for your answers

  5. Here is the final code that works, thanks for your help :)

     

    <?php
    $query = "SELECT costs.item_type, SUM(costs.price) as sum
              FROM costs
              JOIN item_types ON costs.item_type = item_types.id
              GROUP BY costs.item_type";
    $result = mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_assoc($result))
    {
    	$query_item_name = mysql_query("SELECT name FROM item_types WHERE id='".$row['item_type']."'");
    	$item_name = mysql_fetch_array($query_item_name);
    	$item_name = $item_name['name'];
    	$item_totals[$item_name] = $row['sum'];
    }
    
    $item_summery = /*array_sum($item_totals)*/$item_totals;
    
    var_dump($item_totals);
    ?>
    

     

    Your most probly gonna say there was an easier way to do that aswell... :P

  6. Thank you very much =) It works, I only had to change the fact that it wasn't item_type.name I was looking for it was item_type.id because the cost.item_type was refferenced to by ID so now I have something like:

     

         array(3) { [2]=> string(2) "37" [3]=> string(5) "68.46" [4]=> string(2) "40" }
    

     

    Now I just need to think of how to grab the name from the item_types table that holds the item name against the id, but i'm sure that wont be too hard... maybe.

     

    You have made me think about using MYSQL to its full ability! I actualy had never looked in to it enough to realise you could do more complex querys like that, thanks!

  7. Ok, this may be just because I have been programming all day and my mind has gone blank (happens alot), but this is my PHP script:

     

    <?php
    $query_distinct_item_types = mysql_query("SELECT DISTINCT name FROM item_types");
    while($item_types = mysql_fetch_array($query_distinct_item_types)){
    	$distinct_item_types[] = $item_types['name'];
    }
    
    foreach($distinct_item_types as $item){
    	$query_item_total = mysql_query("SELECT item_type, SUM(price) WHERE item_type='$item' FROM costs GROUP BY item_type");
    	while($item_total = mysql_fetch_array($query_total_price)){
    		$item_totals[] = $item_total['SUM(price)'];
    	}
    }
    
    $item_summery = $item_totals;
    ?>
    

     

    $item_summery which is = to $item_totals is returning null, any idea's?

     

  8. But the syntax is wrong and you can't include a, variable... but you can echo it.. Im guessing you want somthing more like this:

     

      <?php
        $a = '2';
        if($_POST['number']==1){echo $a;}
      ?>
    

     

    Or if you are actualy trying to include a file, do what Kira said.

  9. I have sorted it but in a round about way, I have split the $search term up into seperate values using the PHP function explode() using " " (a space) as a delimmiter, so now i have $search_arr[0] as the first word and $search_arr[1] as the second. Then I used this query:

     

    SELECT * FROM customers WHERE (client_id='$_SESSION[client_id]') AND ((forename LIKE '%$search_term%' OR surname LIKE '%$search_term%') OR (forename LIKE '%$search_arr[0]%' AND surname LIKE '%$search_arr[1]%'))
    

     

    woah

     

    But if anyone else knows a better way please let me know =)

  10. Thanks mate that worked well! But what if i wanted the user to be able to type either;

     

    'Craig' or 'Dennis' or 'Craig Dennis'

     

    Is there a way to do:

     

    (forename LIKE '%$search_term%'  OR surname LIKE '%$search_term%') OR (forname AND surname LIKE '%$search_term%')
    

     

    Dyu see what I mean? I know thats not the correct syntax, but is there a way to say forename and surname together and test against them.

  11. Hi guys, having a problem with a search query, I have a customer base, and want to search through by forename and surname using one search query, or every line of address. I want somthing similar to this:

     

    SELECT * FROM customers WHERE client_id='$_SESSION[client_id]' AND (col1, col2, col3) LIKE '%$search_term%
    

     

    This works great if I replace (col1, col2, col3) with one column name like 'forename'. So what is the most simplistic method to do what i'm trying to do?

     

    Thanks in advance!

  12. Awesome thanks guys, and thanks for that artical explaining salt coz' i didn't know what it was. Seems like the best solution to me! But still I dont really see the problem with testing the password in the first place in my script like:

     

    if($password == "imapasswordlol")
    

     

    Coz if the person whos hacking has managed to get to your scripts then your screwed anyway.

  13. Ok.. I have made an admin section for a couple of sites, and it works fine, alough i'm almost certain that the way i have done it is not the "proper way".

     

    What I have done is had a form with a password field that sends the password via POST to another script that checks the password is correct via variable, something like this:

    <?php
    
      $pass = $_POST["pass"];
      $correct = "imapassword";
    
      if($pass == $correct){
        
      //display contents of page
    
      else{
      //return user to login screen
      }
    ?>
    

     

    And then it saves the password into a cookie, that dies either over time or when the browser closes. And then on each page it tests wether that cookie is still there and is correct. When the user wants to log out it just destroys the cookie.

     

    This seems like a really hashed up way of doing it, could anybody let me know the bare essentials for making a similar system, but the "right way". Thankyou in advance

  14. Oops thanks, sorry didn't know that. Thought it would be ok if on same server.

     

    Ok.. so now i have to have:

     

    <?php
        include("../inc_breadcrumb.php");
    ?>
    

     

    In the index.php file in the folder above, but what about folders above that, have they all got to have seperate include functions to just put the right amount of "../" before the file name?

  15. (Well there are a couple of folders up from breadcrumb)

    I was at test/breadcrumb/test2/loldge , in loldge is a file that just has:

     

    <?php
        include("http://www.zephni.com/test/breadcrumb/inc_breadcrumb");
    ?>
    

     

    Which has all of the code that makes the breadcrumb. The URL said excatly where I was (" test/breadcrumb/test2/loldge") but the breadcrumb said:

     

    Home > Test > Breadcrumb > Index

     

    So confused... Thanks for replies

  16. Ok thanks, just one thing though. I can't seem to include this file in other pages because it seems to be running before it is included.

    Like say I am a couple of folders up from /test/breadcrumb/ when i include that script above it seems to only go as far as where the file is sitting, not the current directory.

     

    Is there any reason for that?

  17. Hi, this does work, but I want to check if it's the best way to do it. you can see it here at http://www.zephni.com/test/breadcrumb/. If you don't know, breadcrumbs are what sites use so you can easily navigate back the way you came like:

     

    PHP Freaks Forums » PHP Coding » PHP Coding Help »

     

    Like how you see on your page.

     

    Anywho, this is the PHP script here:

    <?php
    #get server name
    $domain = "http://".$_SERVER['SERVER_NAME'];
    
    #Gets URL and explodes into array
    $crumbs = explode("/",$_SERVER["REQUEST_URI"]);
    
    #echos out the breadcrumbs
    echo "<a href='$domain'>Home</a>"; #always first in line
    foreach($crumbs as $crumb){
    	if($crumb > ""){
    	$tree = null; #reset tree so it can build up again for each foreach (*confuse face*)
    		echo " > ";
    		#all this part below does is capitalize the words and replace certain parts of the words that we don't want, just incase they sneak in.
    		$crumb_text = ucfirst(str_replace(array(".php","_"),array(""," "),$crumb));
    
    		#append folder navigation to link as we foreach through the $crumbs
    		$tree_arr[] = $crumb."/";
    		foreach($tree_arr as $item){
    			$tree .= $item; #Create a string of current $tree
    		}
    
    		#echo out the html for the breadcrumb link
    		echo "<a href='$domain/$tree'>".$crumb_text."</a>";
    	}
    }	
    ?>
    

     

    That is the entire code. I creates like a list of directorys and displays them as links, that are in a relevant path to where you are on the site.

    Please let me know if this is the correct way to do this, thankyou.

  18. Hey, i have made a silly little tester game just to see if i could, its here: http://www.zephni.com/test/pairs its for some guy who is attending college and he was given the assignment to make a game of pairs using PHP to sort the cards and lay them down, and javascript to handle the actual game.

     

    Anyway at the moment, my game sorts out the cards as if they are values from 1 to 52, and picks randomly 18 cards from them. During the game, the cards have to be excatly the same, as in:

     

    if(card_picked1 == card_picked2){

          win pair

    }

     

    that means that both cards would have to be the same number AND suit. But in pairs you have to pick the same number but obviously in a different suit. Any way I have been trying some diff code to pick 18 cards from the pack. It picks 9, and then doubles them up but +'s 13 to the card so it is the same number card.

     

    Here is the code

     

    <?php
    
    $i = 1;
    $total_cards = 18;
    
    #Sorting out cards
    $card_sort = range(1,52);
    
    while($i <= ($total_cards/2)){
    	$pick_card = $card_sort[rand(1,52)];
    
    	if($pick_card !== null){
    		$cards[] = $pick_card;
    	}
    	unset($card_sort[$pick_card]);
    
    	$i = $i+1;
    }
    
    foreach($cards as $card){
    	echo($card."<br/>");
    }
    
    ?>
    

     

    I would of thought that when you unset the number from $card_sort that was picked it would'nt choose it again if($pick_card !== null) but it still chooses the same card twice sometimes. I know I really havent explained this well, but i did my best for 9am...

  19. Rage.

     

    The whole error message reads:

    Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 16 bytes)

     

    Dunno bout you but that doesn't make sense to me!

     

    Anywho I am constantly getting this error when any PHP variables are stored or anything. I'm guessing thats the case coz its saying the error is on line 6 which is:

     

    $card = rand(1,52);

     

    I tried a search on google but just got confused, is there a simple explanation why this is happening? thanks alot guys

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