SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Select and Connection Errors

    Using Apache, PHP and MySql:

    the code

    Form used to build SQL Query:
    ___________________________________________________
    <html><body>

    <form name="stuff" " method="post" action="display.php">

    Fname<input type="text" name="fname"></input><br>
    Lnameinput type="text" name="lname"></input><br>

    <input type="submit" value="click"></input>
    </form>

    </body></html>

    _________________________________________________


    The Query and Results Page
    __________________________________________________
    <?

    $db_name = "test";
    $table_name = "test";

    $connection = @mysql_connect("localhost", "jasond", "jasond") or die ("Could not connect.");

    $db = @mysql_select_db($db_name, $connection) or die ("no db connection");

    $sql = "select * from $table_name where fname like '$fname%' and lname like '$lname%'";

    $result = @mysql_query($sql,$connection) or die ("damn2");

    while ($row = mysql_fetch_array($result)) {

    $fname = $row['fname'];
    $lanme = $row['lname'];

    $display_block .= "
    <b>$fname<b><br>
    <p>$lname</p>
    ";
    }
    ?>
    <html>
    <body>
    <? echo "$display_block"; ?>
    </body>
    </html>

    ______________________________________________________

    This was working locally on my machine, NT Worksation.
    I have the equivalant setup, as far as I can tell on a NT Server now.

    I access the web page over my Intranet and the SQL Select statment will not work. Instead of the returning Records based on my search, it returns all Records in the Data Base.

    Combinations of changing ("localhost", "jasond", "jasond") will either cause a "Could Not Connect Error" or again, the page displaying all records and not what I am searching for.

    Very confused. It works on my machine locally, but when I try to access the Page remortely, the SQL query is ignored, yet displays all records.

    Any ideas????? please.....................

  2. #2
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i cant see how your variables are getting from page input to your processing form.
    i think you need
    $HTTP_POST_VARS["fname, lname"];
    to get your variables across and i'm also not sure about the % sign after your variables shoot me if i'm wrong

  3. #3
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using the % cause it's supposed to work more as a search. But you might be right, I don't know if they are needed.

    the HTTP_POST_VAR section

    where would I put that in the code, searching but if you know off hand it would help a lot

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about putting putting the whole string in one variable?

    $querystr1 = $fname . "%";
    $querystr2 = $lname . "%";
    -- | StEaLThEn |--

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its obvious on your Server Register_Globals are turned off, I suggest putting this at the top of your pages.

    PHP Code:
    <?
    if(count($HTTP_GET_VARS)) extract($HTTP_GET_VARS);
    if(
    count($HTTP_POST_VARS)) extract($HTTP_POST_VARS);
    ?>

    That will give you access to your variables as you are using them in your script above.


    http://www.php.net/extract
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, that did it!!!!

    thanks a bunch

    i put your suggestion in both files and it worked!!!

    3 days of this and finally it's working the way it should!!!

    thanks a lot again!!!!!!!!


Bookmarks

Posting Permissions

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