1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP mysql queery gone wrong - help please

Discussion in 'HTML, Graphics & Programming' started by yoda, 7 Jul 2006.

  1. yoda

    Hitman

    Joined: 18 Oct 2002

    Posts: 858

    Location: Cheshire

    Forgive the coding, i'm just creating the page and it's all gone wrong.....

    here is the PHP script...
    basically, URL search variables are passed to this file.... so thats what all the IF ISSET and GETs are for

    I'm using SPRINTF function to build the sql SELECT statement.
    I created the original code in dreamweaver just with the one WHERE item in the SELECT statement, However I want to search by all the ones I've listed above.

    When loaded, the URL parameters are passed to the page but the page is totally blank dispite the original having a table repeat reagon and their is nothing in the resultant HTML code as shown below.

    The full code is below....

    Can someone tell me what I've done wrong please, I've been trying to track this down for hours.

    Thanks
     
  2. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 29,080

    Location: Back in East London

    Use code tags instead of quote tags please.. that hurts my eyes trying to read it.
     
  3. robmiller

    Capodecina

    Joined: 26 Dec 2003

    Posts: 16,522

    Location: London

    I don't think code tags will solve that :/

    Have you ever heard of a handy structure called the array? It makes things rather a lot easier.

    Replace your whole crazy if/elseif/else blob at the top with something like this:

    Code:
    $fields = array();
    foreach ( $_POST as $key => $val ) {
        $fields[$key] = $val;
        if ( get_magic_quotes_gpc() )
            $fields[$key] = stripslashes($val);
        $fields[$key] = mysql_real_escape_string($fields[$key]);
    }
    
    And update your query to use $fields['Customer_ID'] instead of the tongue-twisting $colname1_customer_search, $fields['Customer_initials'] instead of $colname2_customer_search, etc.