Jump to content

Mysql/Php help need

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
17 replies to this topic

#1
mittalmak

mittalmak

    Newbie

  • Members
  • PipPip
  • 10 posts
hii every body i need help in my script my website.. is here

and the error is
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

<?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
penkomitev

penkomitev

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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

#3
mittalmak

mittalmak

    Newbie

  • Members
  • PipPip
  • 10 posts

penkomitev said:

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
-- 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 ;


#4
penkomitev

penkomitev

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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.

$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
$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:

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

#5
mittalmak

mittalmak

    Newbie

  • Members
  • PipPip
  • 10 posts
here it is

SQL query:  


mysql_query(


'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration'

) OR die(

mysql_error(

)

) 

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 


#6
penkomitev

penkomitev

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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:

$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 :).
You can visit something interesting HERE

#7
mittalmak

mittalmak

    Newbie

  • Members
  • PipPip
  • 10 posts
here it is
SQL query: Documentation


$q = 'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration';



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 


#8
penkomitev

penkomitev

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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

#9
mittalmak

mittalmak

    Newbie

  • Members
  • PipPip
  • 10 posts

penkomitev said:

I need the printed string of $q and the structure of your SQL table in order to help you.

i didn't get u..........

#10
penkomitev

penkomitev

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Well,

you have this as query:

$q = 'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration';

Please in your PHP code do:

$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.
You can visit something interesting HERE

#11
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Adding:
 or die(mysql_error());
To the end of your query will give you more information about the problem...

#12
mittalmak

mittalmak

    Newbie

  • Members
  • PipPip
  • 10 posts

penkomitev said:

Well,

you have this as query:

$q = 'select name as cfgKey, value as cfgValue from '.TABLE_PREFIX. 'configuration';

Please in your PHP code do:


$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.

here is the output
select name as cfgKey, value as cfgValue from qa_configuration

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mittal/public_html/money/includes/application_top.php on line 14

No Categories.

and here is ma website......
mittal.x10hosting.com