Web Design Forum: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' Am getting this error and not sure why Rate Topic: -----

#1 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

  Posted 19 May 2009 - 03:22 PM

Hi Guys,

I'm getting the following errors:

Quote

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\shop\index.php on line 21


Quote

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\shop\index.php on line 21


//NOT SURE WHY this is though....

Here's the two files I have done

NOTE: This is a learning curve for me am just getting to grips with PHP & MySQL, learning from W3Schools.com. So be kind and gentle pls... :help:

Also I have all the books related to this, but still getting stuck on certain things....

index.php
<?php
include 'includes/db.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>Site Title</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="header">
		<img src="images/" alt="" title="" />
	</div>
	<div id="wrapper">
<?php
$query  = "SELECT * FROM photos";
$result = mysql_query($query);
?>

	
	</div>
</body>
</html>


Database Connection: includes/db.php
<?php
$con = mysql_connect("localhost","root","*********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_close($con);
?>


Am doing this using WAMP on PC.

Thanks in advance
Lee
0

#2 User is offline   BritZin 

  • Lord High Guru
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 940
  • Joined: 02-January 09
  • Reputation: 72
  • Gender:Male
  • Location:United Kingdom
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 19 May 2009 - 03:33 PM

You're closing the connection before the file has a chance to run the query!

Remove; "mysql_close($con);" from db.php
and place it at the end of the actual query it's self in index.php.

It might need further fiddiling with though, but from a quick glance, that's what stands out!
0

#3 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 19 May 2009 - 03:37 PM

cheers, i'll try that

thanks dude
0

#4 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 19 May 2009 - 03:42 PM

Next issue i seem to have is, the database ins't showing, there's one dummy product in ther and I have been fiddling arounf for ....erm about 3 hours now trying different ways to get the data to show....

Any idea's ?

Here's my database and tables if you could shed some light on where am going wrong in bringing the data from the database to the index.php file

Database:
--
-- Database: `catalog`
--

-- --------------------------------------------------------

--
-- Table structure for table `photos`
--

CREATE TABLE IF NOT EXISTS `photos` (
  `catalog_number` int(6) NOT NULL,
  `name` varchar(20) NOT NULL,
  `category` varchar(20) NOT NULL,
  `description` varchar(255) NOT NULL,
  `price` decimal(7,2) NOT NULL,
  `pix` varchar(20) NOT NULL DEFAULT 'images/basket.jpg' COMMENT 'Image used for no image',
  PRIMARY KEY (`catalog_number`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `photos`
--

INSERT INTO `photos` (`catalog_number`, `name`, `category`, `description`, `price`, `pix`) VALUES
(1, 'Test Image', 'Test Category', 'Description of the product/image', '12.99', 'noimage.jpg');


Then i tried this: in index.php but nothing showing what have I done wrong ?
I've not shown the rest has it's just HTML
<div id="wrapper">
<?php
$query  = "SELECT * FROM photos";
$result = mysql_query($query);
?>

	
	</div>

0

#5 User is offline   pat24 

  • Guru of nothing important!!
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,183
  • Joined: 29-April 08
  • Reputation: 131
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 19 May 2009 - 09:02 PM

hi lee

Try this and see if you get any output

<div id="wrapper">
	   <?php
	   $result = mysql_query("SELECT * FROM photos")or die(mysql_error());
	   while($row = mysql_fetch_object($result))
	   {
	   
	   echo "$row->catalog_number";
	  
	   echo "$row->name";
	   
	   echo "$row->category";
	   
	   echo "$row->description";
	   
	   }
	   
	   ?>
	   </div>


I an assuming you db connection is somewhere on the page

Pat
0

#6 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 20 May 2009 - 09:06 AM

View Postpat24, on May 19 2009, 22:02, said:

hi lee

Try this and see if you get any output

<div id="wrapper">
	   <?php
	   $result = mysql_query("SELECT * FROM photos")or die(mysql_error());
	   while($row = mysql_fetch_object($result))
	   {
	   
	   echo "$row->catalog_number";
	  
	   echo "$row->name";
	   
	   echo "$row->category";
	   
	   echo "$row->description";
	   
	   }
	   
	   ?>
	   </div>


I an assuming you db connection is somewhere on the page

Pat


Thanks pat yes that worked, but am having trouble showing the image, which I inputted in MySQL no image is showing nor is the £ sign am I missing something ???

Here's my current code:
<div id="column_l">
				<p>Some text here.....</p>
					   <br />
<?php
	   $result = mysql_query("SELECT * FROM photos")or die(mysql_error());
	   while($row = mysql_fetch_object($result))
	   {
	  
	   echo "$row->catalog_number";
	  
	   echo "$row->name";
	  
	   echo "$row->category";
	  
	   echo "$row->description";
	   
	   echo "$row->price";
	   
	   echo "$row->pix";
	  
	   }
	  
?>
<?php mysql_close($con); ?>
		<br /><br />


Am getting this output displayed on the page in browser

1Test ImageTest CategoryDescription of the product/image12.99basket.jpg2This is a titleCategory for this prDescription for this type of product19.99basket.jpg

So the number's are showing but it's all on one line how do I break each line up, also you will see the basket.jpg instead of it showing the actual image, any idea's on how I can do this ??

Cheers
0

#7 User is offline   Faevilangel 

  • Wordpress Ninja.....
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,166
  • Joined: 11-May 09
  • Reputation: 57
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 09:39 AM

below i have added your data into a table so each seperate query gets its own line, the table starts before the query is called and the table is finished once the query is done,

<div id="column_l">
				<p>Some text here.....</p>
					   <br />

 echo "<table>";
<?php
	   $result = mysql_query("SELECT * FROM photos")or die(mysql_error());
	   while($row = mysql_fetch_object($result))
	   {
	   echo "<tr><td>";		  
	   echo "$row->catalog_number";
	  echo "</td>";
		 echo "<td>":
	   echo "$row->name";
	  echo </td>";
		  echo "<td>";
	   echo "$row->category";
	  echo "</td>";
		  echo "<td>";
	   echo "$row->description";
	   echo "</td>";
		  echo "<td>";
	   echo "$row->price";
	   echo "</td>";
		  echo "<td>";
	   echo "$row->pix";
	  echo "</td></tr>";
	   }
	  
?>
<?php mysql_close($con); 
	echo "</table>";  
		<br /><br />

0

#8 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 20 May 2009 - 09:49 AM

Ok tried what you said and I get this view on the webpage

echo ""; echo "
1 Test Image Test Category Description of the product/image 12.99 basket.jpg
2 This is a title Category for this pr Description for this type of product 19.99 basket.jpg
";
0

#9 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 12:31 PM

Why are you in OOP mode?

wherever you have

$row->whatever


it should be

$row['whatever']

0

#10 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 12:31 PM

Plus im not seeing a SELECT database anywhere
0

#11 User is offline   pat24 

  • Guru of nothing important!!
  • PipPipPipPipPip
  • Group: Members
  • Posts: 2,183
  • Joined: 29-April 08
  • Reputation: 131
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 12:34 PM

View Postskidz, on May 20 2009, 13:31, said:

Why are you in OOP mode?

wherever you have

$row->whatever


it should be

$row['whatever']


That code was posted only to see if he was getting any output, it was not meant as a final solution to his problem. :D

Pat
0

#12 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 20 May 2009 - 01:58 PM

I used the
$row['whatever']

but am getting a parse error, and the SELECT database is in another file called db.php (shown below)
#
<?php
$con = mysql_connect("localhost","root","*******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("catalog", $con);

$result = mysql_query("SELECT * FROM photos");
?>

0

#13 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 20 May 2009 - 02:02 PM

I have this in index.php
<br />
echo "<table>";
<?php
	   $result = mysql_query("SELECT * FROM photos")or die(mysql_error());
	   while($row = mysql_fetch_object($result))
	   {
	   echo "<tr><td>";		  
	   echo "$row['catalog_numer'];
	  echo "</td>";
		 echo "<td>";
	   echo "$row['name'];
	  echo "</td>";
		  echo "<td>";
	   echo "$row['category'];
	  echo "</td>";
		  echo "<td>";
	   echo "$row['description'];
	   echo "</td>";
		  echo "<td>";
	   echo "$row['price'];
	   echo "</td>";
		  echo "<td>";
	   echo "$row['pix'];
	  echo "</td></tr>";
	   }
	  
?>
<?php mysql_close($con); ?>
	echo "</table>";  
		<br /><br />


Which is throwing a error:

Quote

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www......


Really appreciate everyone's help so far, like I said at the beginning of the post am totally new too all this and after watching videos and reading books am still stuck and I sometimes get things if shown the correct way by you guys, so I do REALLY appreciate it all, sure you had the same issues when you started out.... :)
0

#14 User is offline   Faevilangel 

  • Wordpress Ninja.....
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,166
  • Joined: 11-May 09
  • Reputation: 57
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 02:29 PM

View Postlstables, on May 20 2009, 15:02, said:

I have this in index.php
<br />
echo "<table>";
<?php
	   $result = mysql_query("SELECT * FROM photos")or die(mysql_error());
	   while($row = mysql_fetch_object($result))
	   {
	   echo "<tr><td>";		  
	   echo "$row['catalog_numer'];
	  echo "</td>";
		 echo "<td>";
	   echo "$row['name'];
	  echo "</td>";
		  echo "<td>";
	   echo "$row['category'];
	  echo "</td>";
		  echo "<td>";
	   echo "$row['description'];
	   echo "</td>";
		  echo "<td>";
	   echo "$row['price'];
	   echo "</td>";
		  echo "<td>";
	   echo "$row['pix'];
	  echo "</td></tr>";
	   }
	  
?>
<?php mysql_close($con); ?>
	echo "</table>";  
		<br /><br />


Which is throwing a error:

Really appreciate everyone's help so far, like I said at the beginning of the post am totally new too all this and after watching videos and reading books am still stuck and I sometimes get things if shown the correct way by you guys, so I do REALLY appreciate it all, sure you had the same issues when you started out.... :)


what line is the code error on ? so we know where to look
0

#15 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 20 May 2009 - 02:33 PM

echo "$row['catalog_numer']; <<<< This line which is line 58 on my page but I haven't put the full code on has rest is just html
0

#16 User is offline   Faevilangel 

  • Wordpress Ninja.....
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,166
  • Joined: 11-May 09
  • Reputation: 57
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 02:53 PM

you don't need the "" around php in an echo, only around html

your code should read
 echo $row['catalog_number'];

0

#17 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 20 May 2009 - 03:56 PM

There's gazzillions of parse errors mate!
0

#18 User is offline   lstables 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 441
  • Joined: 08-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Yorkshire, UK
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 20 May 2009 - 05:37 PM

Thanks all for your time and advice....I will see how I get on
0

#19 User is offline   Pham Duc 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 13-March 10
  • Reputation: 0

Posted 13 March 2010 - 05:31 PM

Hi all guy, there are 2 way to solve this problems.
1. You put all your connect query to your index file, not use include or require for a connect database file to your main file.
May be you can ask why ?
2. Because you don't have permission to execute your connect file by another .php file. You can set permission for all file to 755 (CMOD)

I think it's help :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users