View Full Version : Fatal error: Call to undefined function: dbconnect()
Trusten
07-14-2002, 01:28 PM
if you refer to my 'member login' topic, you will see the link to the tutorial.
http://www.webmasterbase.com/article/319/20
i followed it to a T.
now i keep getting this error when i try to test the database.
Fatal error: Call to undefined function: dbconnect()
i don't even know if it's even connecting. for me, line 55 (where the error is) is this part:
<?php
else:
// Process signup submission
dbConnect('sessions');
i even created a database well the name of the table is 'use', and i placed 'use' there, and STILL no go.
what am i doing wrong?
my hosts give me only one database, which i have a lot of galleries in, is that the problem?
chrisvmarle
07-14-2002, 01:49 PM
Have you included the part wich defines the dbConnect function?
function dbConnect($db="") {
global $dbhost, $dbuser, $dbpass;
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");
if ($db!="" and !@mysql_select_db($db))
die("The site database is unavailable.");
return $dbcnx;
}
You need that function, because you call it in line 55; or you could connect manualy using mysql_connect.
Mzzl, Chris
Trusten
07-14-2002, 02:00 PM
yes. i did
*SCREAMS*!
I've only gotten a member login to work ONCE in my life. ONCE, that's it.
i put the 'user' for the user name i need in order to enter mysql. i put the DATAbase, as the name of the mysql database that's there.
BUT HOW WILL IT KNOW WHICH TABLE TO POINT TO? I DIDN'T SEE IT IN THE CODE.
and why won't it connect to my database
and what's this mean?
<?php
else:
// Process signup submission
dbConnect('sessions');
is that the table?
GRRR!!!
p.s. i'm not angry with you, i'm angry with this STUPID script.
chrisvmarle
07-14-2002, 02:03 PM
Could you post the whole script?
(Ofcourse you can cut out your password and username ;))
Mzzl, Chris
Trusten
07-14-2002, 02:13 PM
thank you
this is the original db script:
<?php // db.php
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "password";
function dbConnect($db="") { global $dbhost, $dbuser, $dbpass;
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");
if ($db!="" and !@mysql_select_db($db))
die("The site database is unavailable.");
return $dbcnx;
}
?>
this is what i've done so far to change it
<?php // db.php
$dbhost = "localhost";
$dbuser = "THE NAME I USE TO ENTER MYSQL";
$dbpass = "THE PWD I USE TO ENTER MYSQL";
function dbConnect($db="") { global $dbhost, $dbuser, $dbpass;
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");
if ($db!="" and !@mysql_select_db($db))
die("The site database is unavailable.");
return $dbcnx;
}
?>
strange that it gives me
$dbhost
etc. etc. but not
$db=
anyhow, and here goes also
the script:
<?php // signup.php
require ("common.php");
require ("db.php");
if (!isset($submitok)):
// Display the user signup form
?>
<html>
<head><title>New User Registration</title></head>
<body>
<h3>New User Registration Form</h3><p><font color=orangered size=+1><TT><B>*</B></TT></font>
indicates a required field</p><form method=post action="<?=$PHP_SELF?>"><table border=0 cellpadding=0 cellspacing=5>
<tr>
<td align=right>
<p>User ID</p>
</td>
<td>
<input name=newid type=text maxlength=100 size=25>
<font color=orangered size=+1><TT><B>*</B></TT></font> </td>
</tr>
<tr>
<td align=right>
<p>Full Name</p>
</td>
<td>
<input name=newname type=text maxlength=100 size=25>
<font color=orangered size=+1><TT><B>*</B></TT></font> </td>
</tr>
<tr>
<td align=right>
<p>E-Mail Address</p>
</td>
<td>
<input name=newemail type=text maxlength=100 size=25>
<font color=orangered size=+1><TT><B>*</B></TT></font> </td>
</tr>
<tr valign=top>
<td align=right>
<p>Other Notes</p>
</td>
<td>
<textarea wrap name=newnotes rows=5 cols=30></textarea> </td>
</tr>
<tr>
<td align=right colspan=2>
<hr noshade color=black>
<input type=reset value="Reset Form">
<input type=submit name="submitok" value=" OK ">
</td>
</tr></table></form>
<?php
else:
// Process signup submission
dbConnect('sessions');
if ($newid=="" or $newname=="" or $newemail=="") {
error("One or more required fields were left blank.\\n".
"Please fill them in and try again."); }
// Check for existing user with the new id
$sql = "SELECT COUNT(*) FROM user WHERE userid = '$newid'";
$result = mysql_query($sql);
if (!$result) {
error("A database error occurred in processing your ".
"submission.\\nIf this error persists, please ".
"contact me@me.com."); }
if (@mysql_result($result,0,0)>0) {
error("A user already exists with your chosen userid.\\n".
"Please try another."); }
$newpass = substr(md5(time()),0,6);
$sql = "INSERT INTO user SET
userid = '$newid',
password = PASSWORD('$newpass'),
fullname = '$newname',
email = '$newemail',
notes = '$newnotes'";
if (!mysql_query($sql))
error("A database error occurred in processing your ".
"submission.\\nIf this error persists, please ".
"contact me@me.com.");
// Email the new password to the person.
$message = "New member
Your personal account for the Me Web Site has been created. To log in, proceed to the following address:
http://www.me.com/
Your personal login ID and password are as follows:
userid: $newid
password: $newpass
You can change your password at any time after you have logged in.
If you have any problems, feel free to contact us at<me@me.com>.
Webmaster";
mail($newemail,"Your Password for the Project Website",
$message, "From:Webmaster <webmaster@ame.com>");
?>
<html>
<head><title> Registration Complete </title></head>
<body>
<p><strong>User registration successful!</strong></p>
<p>Your userid and password have been emailed to
<strong><?=$newemail?></strong>, the email address
you just provided in your registration form. To log in,
click <a href="index.php">here</a> to return to the login
page, and enter your new personal userid and password.</p>
</body>
</html>
<?php
endif;
?>
maybe a slight syntax change
function dbConnect($db) {
global $dbhost, $dbuser, $dbpass;
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");
if ($db!=="") {
@mysql_select_db($db);
return $dbcnx;
}
else {
die('errrr the database has disappeared');
}
}
Maybe trying to pass values in as $db while using ($db="") was
glitching -
Trusten
07-14-2002, 05:38 PM
parse error in ...
no luck. now it gives me a phrase error.
the real error comes here...
Call to undefined function: dbconnect()
which is this part of the code:
dbConnect('sessions');
it keeps teling me it's undefined.
WHERE DO I DEFINE THE DB,. could someone go throught the code and write what i put where.
it keeps telling me that it cannot find my database now, after i've changes some things :(
*cries*
Mouldy_Goat
07-14-2002, 10:05 PM
As you can tell from the PHP highlighting there is clearly something wrong just here:
$message = "New member
Your personal account for the Me Web Site has been created. To log in, proceed to the following address:
<a href="http://www.me.com/" target="_blank">http://www.me.com/</a>
Your personal login ID and password are as follows:
userid: $newid
password: $newpass
You can change your password at any time after you have logged in.
If you have any problems, feel free to contact us at<me@me.com>.
Webmaster";
Try adding backslashes in front of the double quotes inside the string.
Not too sure whether this has anything to do with the error message - but you should fix this anyway, because it won't work if you don't.
Mouldy_Goat
07-14-2002, 10:18 PM
Hmm... this is all a bit weird...
Are you sure that the db.php file is in the same directory?
By the way the $db="" syntax is just a way of making "" a default value for the $db variable if none is passed to the function.
But then it should throw up an error if it couldn't find the file if this was the case, since you're using require.
Try fixing the little problem I noticed and then see if you still get the problem.. I can't see that the two are related though.
applefool
03-25-2003, 01:02 AM
This is the exact same problem i am having - I posted on it, but none of the help seemed to help. Anyway, after another fresh install of rh 8 , with mysql and php. I get this error whenever i try to use mysql_connect()
Fatal error: Call to undefined function: mysql_connect() in /var/www/html/PHP/test2.php on line 6
Line 6 being -
$db = mysql_connect("localhost", "user", "pass");
grr.. haven't gotten this working yet..
applefool
03-26-2003, 02:26 PM
Does anyone look at this stuff?
krycek
03-26-2003, 02:35 PM
applefool - I have looked over your code but the cause of the original error is not immediately apparent, however there are errors in the last piece of code you posted - the quotes are wrongly used, as mouldygoat pointed out.
I totally understand if you want to solve this problem, but I can offer an alternative solution. I have just finished a rewrite (version 2.0) of my security scripts, and I would be happy to let you use them and give me some feedback. It's up to you :)
::] krycek [::
applefool
03-26-2003, 06:40 PM
The bit of code with quote comes right out of a book for php/mysql.
This is just a means of connecting to the mysql db as far as i know.
As i said this is a fresh install of redhat 8, so i am unclear as to why no one else has this problem. Anything i try using the mysql_connect() fails with the above mentioned error. I am positive my php code is not the problem, as i have tried various bits of php code all using mysql_connect() and all return that same error.
Surely, someone must have set up a linux to use mysql and php..
krycek
03-26-2003, 07:33 PM
Lol, I use both windows and linux for my php.
believe me, your code that I and others have pointed at, is wrong, no matter where it came from.
if you ask for help, and you don't believe the answers, that's not our fault!
::] krycek [::
krycek
03-26-2003, 07:35 PM
oh yeah, one thing, with regard to the mysql error....... you have got mysql installed and running yeah? and compiled into php?
simply create a page with <?php phpinfo(); ?> on it and run it. then look at the mysql details.
also, try installing phpMyAdmin. if that works, your system is setup ok.
::] krycek [::
applefool
03-26-2003, 09:37 PM
okay so what is the proper way?
mysql_connect( host, user, pass) gives the same error.
I ran the php info, and it shows "with mysql"
please feel free to look http://rh.applefool.com/PHP/info.php
I really need to get this resolved asap, and can't imagine it should be this difficult.
Nightfire
03-26-2003, 09:48 PM
I don't see where it's installed.
If you look at my phpinfo (http://62.7.164.15/phpinfo.php) (providing you go there within 2 hours of me posting) and scroll down to below the ftp details, you'll see the section on mysql
krycek
03-26-2003, 10:38 PM
Applefool, I have looked at your page and you do not appear to have it installed. Look at Nightfire's page, or mine:
www.xe-group.net/phpinfo.php
You will need to install MySQL :) (and then reinstall PHP)
::] krycek [::
Nightfire
03-26-2003, 11:02 PM
Using krycek's link would work, I just had to reboot
applefool
03-27-2003, 03:34 AM
Can someone explain further? I don't mean to sound retarded, but i definitely have MySQL installed as i have been using it on a CL to create a database, but it is also clear that my phpinfo isn't recognizing it. Is there a specific procedure for installing to make this work?
I would have thought that including mysql with the linux install would have taken care of it..
krycek
03-27-2003, 03:21 PM
well, I always compile PHP from source. that way, I see errors and stuff that arise. However, the RPM should do ok...
I would say, reinstall the latest MySQL, and then reinstall the latest PHP.
then see if it works.
::] krycek [::
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.