Results 1 to 6 of 6

Thread: My SQL Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    4

    My SQL Error

    HI All

    The problem I have got is that I got a table displaying results and I need to insert a form that allows you to update the code, but its displaying the following error code:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in W:\www\Book\book_change_form.php on line 14. Its saying the error is with line 14 which I have highlighted, but read the forums and it doesnt necessarily refer to the room. Hope someone can help, many thanks

    <html><head><title></title></head>
    <body>
    <?php
    include("dbinfo.inc.php");
    $comm=@mysql_connect(localhost,$username,$password);
    $rs=@mysql_select_db($database) or die( "Unable to select database");
    $id=$_POST['id'];

    $sql="SELECT * FROM book WHERE Book_id='$id'";

    //mysql_connect(localhost,$_POST['username'],$_POST['pass']);

    $result=mysql_query($sql);
    $num=mysql_num_rows($result);


    $i=0;
    while ($i < $num) {
    $Title=mysql_result($result,$i,"Title");
    $Cost=mysql_result($result,$i,"Cost");
    $Stock=mysql_result($result,$i,"Stock");
    ?>
    <table width="300" cellpadding="10" cellspacing="0" border="2">
    <tr align="center" valign="top">
    <td align="center" colspan="1" rowspan="1" bgcolor="#ffcc99">
    <h3>Edit and Submit</h3>
    <form action="book_change_record.php" method="post">
    <input type="hidden" name="username" value="<?php print $_POST['username']?>">
    <input type="hidden" name="pass" value="

    <?php print $_POST['pass']?>">
    <input type="hidden" Book_id="ud Book_id" value="<? echo "$Book_id" ?>">
    Title: <input type="text" Title="ud_Title" value="<? print "$Title"?>"><br>
    Cost: <input type="text" Cost="ud_Cost" value="<? echo "$Cost"?>"><br>
    Stock: <input type="text" Stock="ud_Stock" value="<? echo "$Stock"?>"><br>
    <input type="Submit" value="Update">
    </form>
    </td></tr></table>

    <?
    ++$i;
    }
    ?>
    </body>
    </html>

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: My SQL Error

    "but read the forums and it doesnt necessarily refer to the room" I'm not sure what that means or what it has to do with the problem.

    As I see it, for what ever reason, it thinks that $result isn't a result set from a query.

    I'm assuming you've read through this:
    http://us2.php.net/manual/en/functio...l-num-rows.php

    And the entry for mysql_query()
    http://us2.php.net/manual/en/function.mysql-query.php
    Particularly this:
    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

    Might want to make sure your query it executing correctly first.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    4

    Re: My SQL Error

    Thanks for the advice. Have solved the error with the line 14 error. Whats happening now is when updating the requested record its saying the record has been updated but when going to view records its still showing old the original information.

  4. #4
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    448

    Re: My SQL Error

    You will have to show us the code from that page for us to be able to look into it. There is no update query on this page.
    If I helped you please rate me.

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: My SQL Error

    well, you're going to have to show some code for us to see what you might be doing wrong. you probably just have a bad UPDATE query. use [php] and [/php] tags to display code, too.

    edit: had this page open from a few hours ago, didn't realize a reply was already made @_@.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    448

    Re: My SQL Error

    Lol couldnt tell you how many times I have done that.
    If I helped you please rate me.

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