Solved

No support for mysqli on remote server - and I have a problem

Posted on 2008-10-29
5
328 Views
Last Modified: 2013-12-13
Hi all,

I have PHP 5.whatever on my local  machine, the host for a site I'm working on seems to have PHP 4 - or at least it doesn't support the mysql object (when I use mysqli_connect it claims that it is an undefined function).

So I'm just using the standard mysql_connect.  Now, the mysql link seems OK, because in the included database connection definition file, I put in this code:

$dbc = mysql_connect('localhost','user','pass','db');
if (!$dbc){
      echo 'problem';
}

Problem does not get echoed.

In the problematic file (which, by the way, is a form), I've echoed the SQL that is being generated and plugged that straight into the database.  When I do so it works fine.

So somewhere there is a problem, in the code attached below, because 'problem2', as below, DOES echo.  The query syntax is fine, the link SEEMS ok, so where is the problem in the 3 lines in between?

Thanks a lot.  This is driving me a bit nuts :)


$q = "INSERT INTO users (first_name, last_name, company_name, email, telephone) VALUES ('$firstname', '$lastname', '$company', '$email', '$phone')";
		$r = mysql_query($q, $dbc);
		$num = mysql_affected_rows($dbc);
		$id = mysql_insert_id($dbc);
		if (!$r){
		echo 'problem2';
		}

Open in new window

0
Comment
Question by:deafpanda
  • 4
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22832987
instead of:
$r = mysql_query($q, $dbc);

try:
$r = mysql_query($q, $dbc) or die( mysql_error() );

what errors do you see?
0
 

Author Comment

by:deafpanda
ID: 22833101
"No database selected".

Thanks, that was a good idea.

Am I right in guessing that mysql_connect doesn't take a database as the 4th argument, like mysqli_connect does, and so I have to use mysql_select_db?

I hope I am.

Will try igt.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22833214
correct.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22833230
$dbc = mysql_connect('localhost','user','pass') or die( mysql_error() );
mysql_select_db('db') or die(mysql_error());
0
 
LVL 82

Expert Comment

by:hielo
ID: 22833782
glad to help
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question