Results 1 to 5 of 5

Thread: mysql_numrows():

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    mysql_numrows():

    Hi not very experienced at using PHP but i am trying to a bring up a query result which the user has typed in the query themselves into a textarea.

    this is my code

    <?php
    include("dbandy.php");

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

    $dbname = 'db_andrewb';
    mysql_select_db($dbname)or die('error finding DB');

    $QSTRING = $_SERVER['QUERY_STRING'];

    $QSTRING = str_replace('queries=', '',$QSTRING);


    echo urldecode($QSTRING);


    $query = $QSTRING;
    $result = mysql_query($query) or die(mysql_error());


    $number = mysql_numrows($result);

    if ($number == 0) {
    print "Sorry, there were no records matching those criteria";
    } else {
    for($i=0; $i<$number; $i++){
    $degreeid = mysql_result($result,$i,"degreeid");
    $degree_name = mysql_result($result,$i,"degree_name");
    $modid = mysql_result($result,$i,"modid");
    $mod_name = mysql_result($result,$i,"mod_name");
    $studentid = mysql_result($result,$i,"studentid");
    $stud_fname = mysql_result($result,$i,"stud_fname");
    $stud_sname = mysql_result($result,$i, "stud_sname");
    $tutorid = mysql_result($result,$i,"tutorid");
    $tutor_fname = mysql_result($result,$i,"tutor_fname");
    $tutor_sname = mysql_result($result,$i,"tutor_sname");

    print "$degreeid, $degree_name, $modid, $mod_name, $studentid, $stud_fname, $stud_sname, $tutorid, $tutor_fname, $tutor_sname<br>";
    }
    }

    mysql_close();

    ?>

    and when trying to put in a query into the text area like SELECT * FROM student this error message comes up:

    Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource

    Can anyone help me?

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: mysql_numrows():

    use mysql_error() to show the last error that occured from mysql. Could be a problem with your query.


    Also use the [php][/php] tags to make your code easier to read.

  3. #3
    New Member
    Join Date
    Mar 2006
    Posts
    4

    Re: mysql_numrows():

    Use mysql_num_rows() instead of mysql_numrows()

    rgds,
    shan

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: mysql_numrows():

    right i have tried the mysql_num_rows() and still get the same error, but when i put(mysql_error()) next to the mysql_numrows it get up with a bit extra to the error.

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
    You have an error in your SQL syntax near '+*+FROM+student++&submit3=submit' at line 1
    Last edited by AJByrne; Mar 30th, 2006 at 06:03 AM.

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: mysql_numrows():

    You should use $_GET['queries'] instead of the whole query string as this is urlencoded. Also, I do not recommend that you allow users to enter queries freehand into your script.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width