Thread: error.

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    I get this error when I run the php file :

    Warning: 0 is not a MySQL result index in /usr/apache/htdocs/tfl/php/newmastercategory.php3 on line 13


    The code looks like this :

    $result = mysql_query("select * from categories where name+'$name' and where parent_id='0');


    pleASe help.

    Thnx.

    Ranesh.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Herne Bay, Kent, UK
    Posts
    30
    Rep Power
    15
    you've not closed your double quote for a start...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    15
    Try something like this :
    $sql="select * from categories where name=$name and where parent_id='0'
    ";
    $result = mysql_query($sql);

    I think it should work.

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    Nope. Still doesn't work. I get the same error msg. The entire bit of coding is given below. What I'm trying to is this:

    There is a Catalog with the fields: id, parent_id and name.

    All main categories will have a parent_id=0 and unique values for id.

    All sub-categories will have a parent_id= id (of the catefory the belong to).

    Hope this much is clear.


    What I want to do is add a new main category. So, when I input a main category name it should first chk to see if this name already exists. If it does it should say so, if not it should input the requested category name to the database and say that it has done so.


    Here's the coding :


    <html>
    <body>
    <?php

    mysql_connect("tropicalfishlanka.com", tfl, FLT883mv);

    mysql_select_db(tropicalfishlanka_com);

    $sql="select * from categories where name=$name and where parent_id='0'";

    $result=mysql_query($sql);
    $exists=mysql_num_rows($result);
    if ($exists)

    {

    //name already exists

    print ("This category already exists. Please ");
    print ("<a href="..enter_new_master_category.htm">go back </a>");
    print ("and enter a different category name.");
    }

    else
    //category does not exist
    {
    mysql_query("INSERT INTO categories (parent_id, name, description)
    VALUES ('0', '$name', '')
    ");
    print("The new category has been created.");}

    ?>
    </body>
    </html>
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Try this:


    <html>
    <body>
    <?php

    mysql_connect("tropicalfishlanka.com",tfl, FLT883mv);

    mysql_select_db("tropicalfishlanka_com");

    $sql="select * from categories where name='$name' and where parent_id='0'";
    //issue this query.. if your parent_id is an integer field then
    //no need to put ' quotes around the parent_id value
    //ie, parent_id=0

    $result=mysql_query($sql);

    if (mysql_num_rows($result)>0)
    {
    //name already exists

    print ("This category already exists. Please ");
    print ("<a href="..enter_new_master_category.htm">go back </a>");
    print ("and enter a different category name.");
    }else{
    //category does not exist
    mysql_query("INSERT INTO categories (parent_id, name, description)
    VALUES ('0', '$name', '')");
    print("The new category has been created.");
    }
    ?>
    </body>
    </html>


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    Hi Shiju,

    I get the same error on the following line.

    Please help.

    thnx,

    Ranesh.


    if (mysql_num_rows($result)>0)
  12. #7
  13. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    try agian the following

    <html>
    <body>
    <?php

    $con=mysql_connect("tropicalfishlanka.com","tfl","FLT883mv");

    mysql_select_db("tropicalfishlanka_com",$con);

    $sql="select * from categories where name='$name' and where parent_id=0";
    //issue this query.. if your parent_id is an integer field then
    //no need to put ' quotes around the parent_id value
    //ie, parent_id=0

    $result=mysql_query($sql,$con);

    if (mysql_num_rows($result)>0)
    {
    //name already exists

    print ("This category already exists. Please ");
    print ("<a href="..enter_new_master_category.htm">go back </a>");
    print ("and enter a different category name.");
    }else{
    //category does not exist
    mysql_query("INSERT INTO categories (parent_id, name, description)
    VALUES ('0', '$name', '')");
    print("The new category has been created.");
    }
    ?>
    </body>
    </html>




    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    Nope. Error on the same line again.

    I dont understand why. What is your opinion?

    Ranesh.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    15
    <html>
    <body>
    <?php
    $db=mysql_connect("tropicalfishlanka.com","tfl","FLT883mv")or die ("Cannot conect to the database");

    $database=mysql_select_db("tropicalfishlanka_com",$con)
    or die("Unable to select Database. Try later.");
    $sql="select * from categories where name='$name' and where parent_id=0";
    $result=mysql_query($sql);
    if($arr=mysql_fetch_array($result))
    {
    print ("This category already exists. Please ");
    print ("<a href="..enter_new_master_category.htm">go back </a>");
    print ("and enter a different category name.");
    }else{
    //category does not exist
    mysql_query("INSERT INTO categories (parent_id, name, description)
    VALUES ('0', '$name', '')");
    print("The new category has been created.");
    }
    ?>
    </body>
    </html>
    Try this :
    Best of luck

    ------------------
    Nikunj Virani
    MYSQL/PHP/XML
    This is the world of Nikunj

    [This message has been edited by nikunj (edited September 01, 2000).]

Similar Threads

  1. Codepupil
    By Adachic in forum C Programming
    Replies: 3
    Last Post: February 6th, 2004, 06:50 PM
  2. syntax error : identifer 'Hole'
    By bootrecker in forum C Programming
    Replies: 2
    Last Post: February 2nd, 2004, 08:08 AM
  3. Replies: 4
    Last Post: January 28th, 2004, 08:29 AM
  4. mysql: getting error description from error code
    By laker in forum PHP Development
    Replies: 1
    Last Post: January 21st, 2004, 06:03 AM
  5. I don't know what this error message means
    By lcham02 in forum Java Help
    Replies: 2
    Last Post: January 13th, 2004, 11:57 AM

IMN logo majestic logo threadwatch logo seochat tools logo