Solved

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

Posted on 2008-10-29
5
329 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 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