0

I'm getting the following error while connecting to my SQL database:

function mysql_query($query) {
$dbhost = "localhost";
$dbuser = "p39438_***";
$dbpass = "password";
$dbname = "p31417_***";

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname); }

Using mysql_query gives me this error:

Cannot redeclare mysql_query() in /home/p39438/domains/*/public_html/_/includes/functies.php on line 10

Daan Verberne
  • 45
  • 1
  • 8
  • 1
    `mysql_select_db()` is not deprecated, only `mysql_selectdb()` is... As to the rest, you're not doing any error checking. Add error checking to see what the problem is. Also, your code is susceptible to SQL injection. http://php.net/manual/en/security.database.sql-injection.php – Pekka Sep 29 '11 at 15:16
  • Correct, mysql_db_query is however. – Daan Verberne Sep 29 '11 at 15:31

3 Answers3

2

Try mysql_query() not just query(). Also, don't put POST variables directly into a SQL query. That's a very bad idea.

James
  • 13,092
  • 1
  • 17
  • 19
  • using mysql_query gives me the following error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'@'localhost' (using password: NO) in /home/p39438/domains/***/public_html/_/includes/dbUpdate.php on line 20 – Daan Verberne Sep 29 '11 at 15:21
  • Do you have permissions to perform that sort of query? Has the connection definitely worked in the first place? – James Sep 29 '11 at 15:23
  • I am using the deprecated query function for a lot of websites in the past. I assume it will work. – Daan Verberne Sep 29 '11 at 15:24
  • It's deprecated. Don't use it. – James Sep 29 '11 at 15:25
  • I know, that's why i am trying to fix it. I don't get why i'm getting the errors for permission..? – Daan Verberne Sep 29 '11 at 15:27
  • The error message suggests you are trying to connect to the database as "apache" without using a password. – James Sep 29 '11 at 15:35
1

You haven't actually EXECUTED your query:

$sql = "....";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
Marc B
  • 356,200
  • 43
  • 426
  • 500
1

The function is mysql_query not query. There's a theme with these mysql function names...

fire
  • 21,383
  • 17
  • 79
  • 114