www.webdeveloper.com
Results 1 to 9 of 9

Thread: echo text from sql query

  1. #1
    Join Date
    Feb 2006
    Posts
    170

    echo text from sql query

    i'm having trouble echoing text from the following sql query

    <?php
    require("auth_admin.inc.php");
    require("../conn.inc.php");

    $requesteduser = $_POST["username"];

    $queryq1 = "Select * from user_info WHERE username = $requesteduser";

    $resultq1 = mysql_query($queryq1);

    ?>

    i've tried lots of ways todo it, which way works lol

  2. #2
    Join Date
    Feb 2003
    Location
    Aberdeen, Washington, USA
    Posts
    1,859
    Try this:
    PHP Code:
    <?php
    require("auth_admin.inc.php");
    require(
    "../conn.inc.php");

    $requesteduser $_POST["username"];

    $queryq1 "Select * from user_info WHERE username = $requesteduser";
    $resultq1 mysql_query($queryq1);

    while(
    $r mysql_fetch_array($resultq1)) {
        echo(
    $r["field-name-here"]);
    }
    ?>
    Where it says "field-name-here" you would put the name of the field in the MySQL database you want to echo.

  3. #3
    Join Date
    Feb 2006
    Posts
    170
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\admin\user_trackingresults.php on line 10

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,174
    That error means your query failed to execute. Try adding some debugging:
    PHP Code:
    $resultq1 mysql_query($queryq1) or die("Query Failed: $queryq1 - " mysql_error()); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Feb 2006
    Posts
    170
    Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\admin\user_trackingresults.php on line 9

    line 9 is that line ^^

    $resultq1 = mysql_query($queryq1) or die("Query Failed: $queryq1 - " mysql_error());

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,174
    Oops!
    PHP Code:
    $resultq1 mysql_query($queryq1) or die("Query Failed: $queryq1 - " mysql_error()); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Feb 2006
    Posts
    170
    now i get

    Query Failed: Select * from user_info WHERE chris = username - Unknown column 'chris' in 'where clause'

    ive tried $requesteduser = username either way round and i get the same the error
    the column should be username
    Last edited by cashton2k; 02-15-2006 at 05:57 PM.

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,174
    Try this:
    PHP Code:
    $queryq1 "Select * from user_info WHERE username = '$requesteduser'"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Feb 2006
    Posts
    170
    is there a way to use lots of echcos without having to do the whole sql query again? The first one works fine but then it ignores the rest

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles