Solved

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

Posted on 2008-10-29
5
326 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
Comment Utility
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
Comment Utility
"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
Comment Utility
correct.
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
$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
Comment Utility
glad to help
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

10 Experts available now in Live!

Get 1:1 Help Now