Question

I keep getting this error:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'mcabinet'@'localhost' (using password: NO) in /home/mcabinet/public_html/games/db_edit/airportmadness4.php on line 3

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/mcabinet/public_html/games/db_edit/airportmadness4.php on line 3
No Database found.

Here is my entire .php page:

<?php
include("../templates/base/template2/mysql_connect.php");




$gametitle = "Airport Madness TEST";
$gamedescription = "DESCRIPtion testing a description. LOL !";
$image1url = "http://website-gamesite.com/games/images/lhfdsjk.jpg";
$categorycode = "adv";
$gametitle2 = "airportmadnesstest";


mysql_query("INSERT INTO Games VALUES (null,'$gametitle','$gamedescription','$image1url','$categorycode','0','$gametitle2'") or die ("Error Inserting Values into the Games Table");

?>

Thanks! I am just beginning with PHP and MySQL.

EDIT: Here is the contents of the include file:

<?php

$db_host = "localhost";
$db_username = "mcabinet_admin";
$db_password = "4jf8ido9A";
$db_name = "mcabinet_games";

@mysql_connect($db_host,$db_username,$db_password) or die ('MySQL Not found // Could Not Connect.');
@mysql_select_db("$db_name") or die ("No Database found.");


?>

After editing with your tips, I still receive the error.

EDIT: I've made more changes. It is weird because when I get content from the database, the content is displayed fine, but with the errors still showing. And when I run the separate script, trying to add rows, it simply will not even connect.

Was it helpful?

Solution 5

RESOLVED!!! The Fix:

Simple Change from:

mysql_query("INSERT INTO Games VALUES (null,'$gametitle','$gamedescription','$image1url','$categorycode','0','$gametitle2'") or die ("Error Inserting Values into the Games Table");

to:

mysql_query("INSERT INTO Games VALUES (null,'$gametitle','$gamedescription','$image1url','$categorycode','0','$gametitle2')") or die ("Error Inserting Values into the Games Table");

OTHER TIPS

Try to move the include above the first query row! Like this

<?php
  include("../templates/base/template2/mysql_connect.php");
  $query = mysql_query("SELECT * FROM Games WHERE id = '1' "); 

To, make a MySQL-request you need to be connected first.

Here's the problem:

mysqli_connect('$db_host','$db_username','$db_password')
    or die ('MySQL Not found // Could Not Connect.');

This should be:

mysql_connect($db_host, $db_username, $db_password)
    or die ('MySQL Not found // Could Not Connect.');

Since you've single-quoted your strings, you end up passing string literals of '$db_host' (etc) rather than the values you intended.

Also, it seems you are connecting with mysqli but running queries using mysql. I'd guess that it would be worth using one or the other - they're two different libraries.

Try this:

<?php
$db_host = "localhost";
$db_username = "mcabinet_admin";
$db_password = "4jf8ido9A";
$db_name = "mcabinet_games";

mysql_connect($db_host,$db_username,$db_password) or die ('MySQL Not found // Could Not Connect.');
mysql_select_db("$db_name") or die ("No Database found.");


$gametitle = "Airport Madness TEST";
$gamedescription = "DESCRIPtion testing a description. LOL !";
$image1url = "http://website-gamesite.com/games/images/lhfdsjk.jpg";
$categorycode = "adv";
$gametitle2 = "airportmadnesstest";


mysql_query("INSERT INTO Games VALUES (null,'$gametitle','$gamedescription','$image1url','$categorycode','0','$gametitle2'") or die ("Error Inserting Values into the Games Table");

?>

Also it appears that ur user is set to not use a password in phpmyadmin, would that be correct?

You should establish a connection before running a query:

1) $link = mysqli_connect($host, $username, $password)
2) mysqli_select_db($link, $db_name);
3) $result = mysqli_query($link, $query);

An interesting scenario is this

<h1>Some heading</h1>
<?php
    insert_data(a1,b1);
?>
<h2>other html stuff</h2>
<?php
    include('database_connnection.php'); <--- problem is this line

    function insert_data(a1,b1)
    {
         Query = "Insert INTO MYTABLE VALUES(a1,b1)";
    }
?>

The above code will give error because insert_data() function is called ahead of invoking the include(database...) as it comes further down the code, hence you will get error. The fix is to move include(database) inside the function or ahead of invoking insert_data query

<?php

    function insert_data(a1,b1)
    {
         include('database_connnection.php');
         Query = "Insert INTO MYTABLE VALUES(a1,b1)";
    }
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top