Page 1 of 1

Strange MySQL Error with PHP

Posted: Sun Oct 10, 2010 2:19 am
by pathachiever11
Hi. I recently had to implement a database search to my client’s website. I am new to MySQL and PHP, as I’ve usually dealt with ASP.Net.

I am getting the following error:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/*****/public_html/***/mysql.php on line 69
To connect, I am using the following code and it seems to work fine, no error.

Code: Select all

$dbhost = 'localhost:3306';
$dbuser = 'DBUSER';
$dbpass = 'DBPASS';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
  $conId = $conn;
$dbname = 'tulipus1_products';
mysql_select_db($dbname) or die (mysql_error());

To search I am using the following code:

Code: Select all

$query = ‘SOME SEARCH QUERY’;
$this->result=mysql_query("SELECT * FROM products where Description LIKE '%$query%'",$this->conId) or die(mysql_error());
return new Result($this,$this->result) or die(mysql_error());
This is not the full code, but the summary of all the code that has been used so far.

I have done a lot of research on the error :banghead: and tried many things, but it doesn’t make sense to me. I have tried the same query on phpMyAdmin and it worked fine.

Please Help.
Thanks in advance!

Re: Strange MySQL Error with PHP

Posted: Sun Oct 10, 2010 11:35 am
by Darhazer
Where you are assigning $this->conId ?

Re: Strange MySQL Error with PHP

Posted: Sun Oct 10, 2010 4:07 pm
by pathachiever11
I am actually setting $conId = $conn; I don't know if that can be the problem.

Re: Strange MySQL Error with PHP

Posted: Mon Oct 11, 2010 3:30 pm
by DigitalMind
show full mysql.php

Re: Strange MySQL Error with PHP

Posted: Mon Oct 11, 2010 10:24 pm
by pathachiever11
Actually, I was able to look at an online article and change the code a bit based on the article. That solved my problem. It had to do something with the way I was connecting to the database. I don't know what, but I am happy that the nightmare is over :)

Thanks for offering your help.