Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Mysql/Php help need

  1. #1
    mittalmak is offline Newbie
    Join Date
    Aug 2007
    Posts
    10
    Rep Power
    0

    Mysql/Php help need

    hii every body i need help in my script my website.. is here

    and the error is
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mittal/public_html/includes/application_top.php on line 14
    No Categories.

    and here is th appalication_top.php

    Code:
    <?php
    
    include('config.php');
    include('functions.php');
    
    
    // Connect to database
    $dbConnection = mysql_pconnect(DATABASE_HOST, DATABASE_USER, DATABASE_PASS) or trigger_error(mysql_error(),E_USER_ERROR);
    mysql_select_db(DATABASE_NAME, $dbConnection);
    
    
    // set the application parameters
    $configuration_query = mysql_query('select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'configuration');
    while ($configuration = mysql_fetch_array($configuration_query)) {
    define($configuration['cfgKey'], $configuration['cfgValue']);
    }
    
    
    // Get parameters
    $keyword=db_prepare_input($_GET['k']);
    $category=db_prepare_input($_GET['c']);
    $page=db_prepare_input($_GET['p']);
    
    // Get category info if specified
    if (!empty($category)){
    // Get Category Colour and Image
    // Check if keyword exists in database
    $cat_query_sql = "select * from " . TABLE_PREFIX . "categories where id='" . $category . "'" ;
    $cat_query = mysql_query($cat_query_sql) ;
    $cat = mysql_fetch_array($cat_query);
    }
    
    // Get category info if specified
    if (!empty($keyword)){
    
    $keyword_query_sql = "select * from " . TABLE_PREFIX . "keywords where id = '" . $keyword . "'";
    $keyword_query = mysql_query($keyword_query_sql) ;
    $keyword_row = mysql_fetch_array($keyword_query);
    $num_keyword_rows = mysql_num_rows($keyword_query);
    
    //if ($num_keyword_rows==0) {
    //die ('Invalid Keyword Specified.');
    //}
    }
    
    
    
    // Within a Category
    if (!empty($category)){
    
    if ($cat['useimage'] ==1){ // Default image
    $catimage='images/categories/titleimage.jpg';
    }
    elseif ($cat['useimage'] ==2){// Uploaded image
    $catimage='images/categories/' . $cat['image'];
    }
    else {
    $catimage='';
    }
    }
    else { // Main page
    
    if (CFG_USEIMAGE==1) {
    $catimage = 'images/categories/titleimage.jpg';
    }
    elseif (CFG_USEIMAGE==2 && CFG_IMAGE !='' && file_exists('images/categories/' . CFG_IMAGE)){
    $catimage= 'images/categories/' . CFG_IMAGE;
    }
    else {
    $catimage='';
    }
    
    }
    
    // Set page title
    if (!empty($cat['category'])){
    $title=$cat['category'];
    }
    else {
    
    $title = CFG_TITLE;
    }
    
    // Use colour if specified, else use default
    if (!empty($cat['colour'])){
    $catcolour=$cat['colour'];
    }
    else {
    $catcolour= CFG_COLOUR;
    }
    
    
    
    
    
    
    
    ?>
    plz help

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0
    Print your sql query a look what it is and try to execute it trough PhpMyAdmin or the one you are using.
    You can visit something interesting HERE

  4. #3
    mittalmak is offline Newbie
    Join Date
    Aug 2007
    Posts
    10
    Rep Power
    0
    Quote Originally Posted by penkomitev View Post
    Print your sql query a look what it is and try to execute it trough PhpMyAdmin or the one you are using.
    r u talking of creat_table.sql file the here it is
    Code:
    -- phpMyAdmin SQL Dump
    -- version 2.8.0.3
    -- http://www.phpmyadmin.net
    -- 
    -- Host: localhost
    -- Generation Time: Aug 10, 2007 at 11:08 AM
    -- Server version: 4.1.18
    -- PHP Version: 5.1.2
    -- 
    -- Database: `misc`
    -- 
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `qa_admin`
    -- 
    
    CREATE TABLE `qa_admin` (
      `id` tinyint(4) NOT NULL auto_increment,
      `user` varchar(64) NOT NULL default '',
      `pass` varchar(64) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    
    -- 
    -- Dumping data for table `qa_admin`
    -- 
    
    INSERT INTO `qa_admin` (`id`, `user`, `pass`) VALUES (1, 'admin', '1a1dc91c907325c69271ddf0c944bc72');
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `qa_categories`
    -- 
    
    
    CREATE TABLE `qa_categories` (
      `id` int(11) NOT NULL auto_increment,
      `category` varchar(64) NOT NULL default '',
      `useimage` tinyint(4) default NULL,
      `image` varchar(64) NOT NULL default '',
      `colour` varchar(16) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
    
    -- 
    -- Dumping data for table `qa_categories`
    -- 
    
    INSERT INTO `qa_categories` (`id`, `category`,`useimage`, `image`, `colour`) VALUES (4, 'Health & Fitness',2, 'tennis_ball.jpg', '577f10'),
    (5, 'Cars & Driving',2, 'cat_car.jpg', 'c8541f'),
    (6, 'Travel & Holidays',2, 'globe.jpg', '25aee8');
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `qa_keywords`
    -- 
    
    CREATE TABLE `qa_keywords` (
      `id` int(11) NOT NULL auto_increment,
      `keyword` varchar(64) NOT NULL default '',
      `categoryid` int(11) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;
    
    -- 
    -- Dumping data for table `qa_keywords`
    -- 
    
    INSERT INTO `qa_keywords` (`id`, `keyword`, `categoryid`) VALUES (1, 'buy used car', 5),
    (2, 'buy new car', 5),
    (3, 'selling a car', 5),
    (4, 'driving license', 5),
    (5, 'learning to drive', 5),
    (10, 'health spa', 4),
    (11, 'sports club', 4),
    (12, 'swimming', 4),
    (13, 'football', 4),
    (14, 'gymnasium', 4),
    (15, 'tennis club', 4),
    (16, 'golf course', 4),
    (17, 'cheap flights', 6),
    (18, 'cheap hotels', 6),
    (19, 'package holidays', 6),
    (20, 'driving directions', 6),
    (21, 'camp sites', 6);
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `qa_questions`
    -- 
    
    CREATE TABLE `qa_questions` (
      `id` int(11) NOT NULL auto_increment,
      `keywordid` int(11) NOT NULL default '0',
      `questionid` varchar(32) NOT NULL default '',
      `subject` varchar(128) NOT NULL default '',
      `content` text NOT NULL,
      `timestamp` varchar(16) NOT NULL default '',
      `category` varchar(32) NOT NULL default '',
      `answer` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=240 ;
    
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `qa_configuration`
    -- 
    
    CREATE TABLE `qa_configuration` (
      `id` tinyint(4) NOT NULL auto_increment,
      `name` varchar(32) NOT NULL default '',
      `value` varchar(128) default NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;
    
    -- 
    -- Dumping data for table `qa_configuration`
    -- 
    
    INSERT INTO `qa_configuration` (`id`, `name`, `value`) VALUES (2, 'CFG_COLOUR', 'c8541f'),
    (4, 'CFG_IMAGE', 'titleimage.jpg'),
    (5, 'CFG_SHOWSIMILAR', '1'),
    (6, 'CFG_SHOWSIMILARAMT', '5'),
    (7, 'CFG_TITLE', 'Questions Answered'),
    (8, 'CFG_ADSENSEID', 'pub-xxxxxxxxxxxxxxxx'),
    (9, 'CFG_MAXQUESTIONS', '40'),
    (10, 'CFG_MAXIMAGES', '200'),
    (11, 'CFG_YAHOOAPIID', 'YahooDemo'),
    (12, 'CFG_FLICKRAPIID', '7cf20bdc57f9b6e9e3ce3972beae9610'),
    (13, 'CFG_SHOWQUESTIONS', '8'),
    (14, 'CFG_USEAVATAR', '2'),
    (15, 'CFG_AVATARIMAGE', NULL),
    (16, 'CFG_AVATARWIDTH_Q', '80'),
    (17, 'CFG_AVATARHEIGHT_Q', '80'),
    (18, 'CFG_SHOWAVATAR_Q', '1'),
    (19, 'CFG_SHOWAVATAR_A', '1'),
    (20, 'CFG_AVATARHEIGHT_A', '80'),
    (21, 'CFG_AVATARWIDTH_A', '80'),
    (22, 'CFG_MATCHKEYWORDS', 'all'),
    (23, 'CFG_REGION', 'us'),
    (24, 'CFG_USEIMAGE', '1'),
    (25, 'CFG_MODIFYCONTENT', NULL);
    
    
    -- 
    -- Host: localhost
    -- Generation Time: Aug 25, 2007 at 11:42 AM
    -- Server version: 4.1.18
    -- PHP Version: 5.1.2
    -- 
    -- Database: `misc`
    -- 
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `qa_images`
    -- 
    
    CREATE TABLE `qa_images` (
      `id` int(11) NOT NULL auto_increment,
      `keywordid` int(11) NOT NULL default '0',
      `imageurl` text NOT NULL,
      `imagealt` varchar(64) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

  5. #4
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0
    Nope, query means the SQL string you are using for getting the results. An example of query is "SELECT user_id WHERE email='something@abv.bg'"

    So, the script breaks at line 14, I calculated that this is your first query.

    Code:
    $configuration_query = mysql_query('select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'configuration');
    But you can't print it that way. Make it
    Code:
    $q = 'select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'configuration');
    print $q;

    Look at the result, printed in the browser and copy it into phpMyAdmin SQL section(second on the menu after you choose your database) and execute it. PhpMyAdmin will show your error. Alternatively make your query that way:

    Code:
    mysql_query('select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'configuration') or die(mysql_error());
    and the error will be shown if the query fail to execute.
    You can visit something interesting HERE

  6. #5
    mittalmak is offline Newbie
    Join Date
    Aug 2007
    Posts
    10
    Rep Power
    0
    here it is

    Code:
    SQL query:  
    
    mysql_query(
    
    'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration'
    ) OR die(
    mysql_error(
    )
    )
    Code:
    MySQL said:  
    
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_query('select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'c' at line 1

  7. #6
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0
    Wow,
    I am sure you have done mysql_query(mysql_query));
    Look at my previous post and espescially on the value of $q. Print just $q and copy the printed text from the browser. Then this text execure in phpMyAdmin.


    Edit: I am sorry there is one ')' but you could see there isn't '(', so it is unnecessary.

    So make it:

    Code:
    $q = 'select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'configuration';
    print $q;
    to get the text of the query in the browser. Then execute it and write again .
    Last edited by penkomitev; 01-01-2008 at 08:01 AM.
    You can visit something interesting HERE

  8. #7
    mittalmak is offline Newbie
    Join Date
    Aug 2007
    Posts
    10
    Rep Power
    0
    here it is
    Code:
    SQL query: Documentation
    
    $q = 'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration';
    Code:
    MySQL said: Documentation
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$q = 'select name as cfgKey, value as cfgValue from ' . TABLE_PREFIX . 'configur' at line 1

  9. #8
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0
    I need the printed string of $q and the structure of your SQL table in order to help you.
    You can visit something interesting HERE

  10. #9
    mittalmak is offline Newbie
    Join Date
    Aug 2007
    Posts
    10
    Rep Power
    0
    Quote Originally Posted by penkomitev View Post
    I need the printed string of $q and the structure of your SQL table in order to help you.
    i didn't get u..........

  11. #10
    penkomitev is offline Learning Programmer
    Join Date
    Dec 2007
    Location
    Plovdiv, Bulgaria
    Posts
    31
    Rep Power
    0
    Well,

    you have this as query:

    Code:
    $q = 'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration';
    Please in your PHP code do:

    Code:
    $q = 'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration';
    print $q;
    The result of the query will appear in the browser. I want to look at this result.

    I also need the structure of your table(I mean the fields you have, what are their types and so on. - You can extract it via PHPMyAdmin. Just click on your table, then Export, click Ok, and the SQL structure will appear as a query. Then copy it here).

    Edit: Sorry, you have posted your SQL structure in your previous post. So just the value of $q.

    Edit2: After reading the SQL strucure, I think only the print will bring enough information. It is possible this TABLE_PREFIX not to have the right value.
    Last edited by penkomitev; 01-03-2008 at 07:43 AM.
    You can visit something interesting HERE

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Use PDO for mysql or standar mysql functions?
    By lol33d in forum PHP Development
    Replies: 7
    Last Post: 05-07-2011, 08:41 PM
  2. Replies: 1
    Last Post: 10-20-2010, 12:38 AM
  3. [C#]MySQL] Host '****' is not allowed to connect to this MySQL server
    By ZaroX in forum Database & Database Programming
    Replies: 2
    Last Post: 02-16-2010, 08:34 PM
  4. Replies: 0
    Last Post: 01-26-2009, 11:14 AM
  5. MYSQL CheatSheet - A must for MySQL Users
    By reachpradeep in forum Database & Database Programming
    Replies: 1
    Last Post: 03-03-2007, 01:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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