Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php email 2 26
wamp versus xampp 4 44
Session timeout 5 13
How can I echo a PHP variable in AJAX function? 7 32
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

912 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now