Solved

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

Posted on 2008-10-29
5
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

738 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