Page 1 of 1
mysql_query error
Posted: Wed Mar 28, 2007 5:24 pm
by zyklon
i just revisiteed some old code i had, and apparently forgotten alot of php. anyhow, i have a warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) error and a Warning: mysql_query() [function.mysql-query]: A link to the server could not be established error. i am using xampp and include a config file,
Code: Select all
<?
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("(i took name out)") or die(mysql_error());
?>
the following is the error and the lines related to it;
Code: Select all
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM user WHERE username = '$usercheck'")
or die();
$check2 = mysql_num_rows($check);
Posted: Wed Mar 28, 2007 5:26 pm
by RobertGonzalez
That error message suggests you are trying to connect as a user named ODBC. Is that the case. Also, did you change the users password? What version of mysql are you running?
Posted: Wed Mar 28, 2007 5:43 pm
by zyklon
xampp 1.6.0a is 5.0.33, or at least that what phpmyadmin says.
Posted: Wed Mar 28, 2007 5:54 pm
by RobertGonzalez
Can you see your database in phpMyAdmin?
Posted: Wed Mar 28, 2007 5:59 pm
by zyklon
yup, i have it empty, but yes.
Posted: Wed Mar 28, 2007 6:03 pm
by RobertGonzalez
Then you should be able to add/edit users in phpMyAdmin. Or at the very least, use the phpMyAdmin credentials to get into the database that you are wanting to connect to.
Posted: Wed Mar 28, 2007 6:07 pm
by zyklon
i added a user using it, nothing, should i get php4 instead, would that do anything?
note: i solved it! i swapped to php4 and mysql4!
Posted: Wed Mar 28, 2007 6:29 pm
by RobertGonzalez
Sorry, I don't think I came across correctly. The database users, you should be able to edit those so that your script can actually connect to the app. phpMyAdmin is a PHP application that is connecting to MySQL. The same way it does it your app can do it, as long as you use the same credentials. Or you can actually go into the database users admin piece and change the password for the user you are attempting to connect with and try that.
Posted: Wed Mar 28, 2007 6:30 pm
by volka
zyklon wrote:Access denied for user 'ODBC'@'localhost' (using password: NO)
When there is no mysql connection mysql_query tries to establish a default connection.
'ODBC'@'localhost' strongly indicates this default connection.
Replace <? by <?php
mysql_connect returns a link resource, store it and use it is subsequent calls
Have a read of
http://en.wikipedia.org/wiki/SQL_injection and use mysql_real_escape_string
Code: Select all
<?php
$mysql = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("secret or stupid name", $mysql) or die(mysql_error());
?>
...
<?php
require 'config.php';
$usercheck = mysql_real_escape_string($_POST['username'], $mysql) or die(mysql_error());
$query = "SELECT username FROM user WHERE username = '$usercheck'";
$check = mysql_query($query, $mysql) or die(mysql_error().': '.$query);
$check2 = mysql_num_rows($check);
?>