+ Reply to Thread
Results 1 to 7 of 7

Thread: Help with PHP

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    2

    Default Help with PHP

    hey people.
    I'm having problems in my php code. I'm using WAMP on my laptop and my code doesnt seem to be working I end up with this error message:

    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\new\test1.php on line 43

    I cant seem to figure out what the problem is? is anybody able to help me??

    Heres my code for test1.php:

    <?php


    $matchtype = $_POST['match'];

    $usertext = $_POST['text'];


    $connection = mysql_connect("localhost","root","") or exit ('Could not connect ('.mysql_errno().'): '.mysql_error());



    $db = mysql_select_db("");


    if ($matchtype == "room") {

    $query = "select * from laboratories where roomnu like '%".$usertext."%'";

    }

    else if ($matchtype == "building") {

    $query = "Select * from laboratories where building like '%".$usertext."%'";
    }

    else {

    $query = "Select * from laboratories where building like '%".$usertext."%'";
    }





    $result = mysql_query($query);






    while($row = mysql_fetch_assoc($result))
    {
    echo ($row ['roomnu']);
    }


    mysql_close();

    ?>





    Some help would be highly appreciated thankyou.
    Last edited by blingd; 03-19-2009 at 03:51 AM.

  2. #2
    Moderator
    Join Date
    Mar 2007
    Location
    Southern California
    Posts
    150

    Default

    It looks like it is complaining about

    PHP Code:
    while($row mysql_fetch_assoc($result))
    {
    echo (
    $row ['roomnu']);

    All the best,
    ManagerJosh
    Gaming Hosting Director of
    SimGames.net, Owned and Operated by Steadfast Networks

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    2

    Default

    Yeah its complaining about the mysql_fetch_assoc

    I tried everything like changing the assoc to row but it still gave me the same error message.

  4. #4
    Happy Steadfast Client
    Join Date
    Jan 2006
    Location
    Miami, Fl
    Posts
    125

    Default

    Warning: mysql_fetch_row(): will give you error if the SQL had an uncaught error. So basically $result doesn't exist.

    Try "$result = mysql_query($query) or die(mysql_error());" and see what happens
    [ JUSTIN ]
    [ justechnology llc ]
    [ WEB DESIGN / DEVELOPMENT, TECHNICAL CONSULTING, & BUSINESS WEB HOSTING
    ]
    [ when will apple? ]
    [ GUESS THE RELEASE DATE AND GET THE SCOOP ON APPLE'S NEW PRODUCTS
    ]

  5. #5
    Member
    Join Date
    Jan 2008
    Posts
    36

    Default

    Make sure your sql queries are valid. I usually see this when I've goofed on the SQL query and it's not a valid query.

    You could echo $query; and then copy/paste the query into a sql client to see what it returns.

  6. #6
    Junior Member
    Join Date
    Mar 2009
    Posts
    1

    Default

    Errr... A bit old topic, however...

    $db = mysql_select_db("");
    This is the most obvious problem I see. You're not selecting a database. Why is this?

    Second issues are your post values. You aren't sanitizing them. Do that.

  7. #7
    anurdh65
    Guest

    Default

    HI

    can anybody help me to retrieve the ip address using php code

+ Reply to Thread

Posting Permissions

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