Reply
"Call to undefined function" error. Do I need to link my webpage to a database?
Old 11-11-2004, 12:45 PM "Call to undefined function" error. Do I need to link my webpage to a database?
Skilled Talker

Posts: 79
Hello

i am trying to set up a database on my home computer (to categorise books). I have it installed and, using mySQL in command line I can add lines etc.

When trying to add data through a form, I get the following error:

Fatal error: Call to undefined function: mysql_connect() in /home/hamish/public_html/db_books/sendtodb.php on line 21

Here are lines 8 to 23:
Code:
//get variables from index.php form in previous page
$author = $_REQUEST['author'];
$title = $_REQUEST['title'];
$year = $_REQUEST['year'];
$genre = $_REQUEST['genre'];

//set variables
$host = "localhost";
$user = "hc_books_user";
$password = "password";
$dbname = "hc_books";
$tablename = "books";

$Link = mysql_connect ($host, $user, $password); //line 21

$Query = "INSERT into $tablename values ('0', '$author', '$title', '$year', '$genre')";
As far as I can see, the $Link variable has all the data to work.

I wondered if I somehow needed to link the webpage to the database (or is that covered by localhost?) Or do I need to install a mySQL module for my Apache?

Form is at http://hamishnet.homelinux.com/~hamish/db_books/ .

the mySQL server is definately running and, AFAIK, I have correctly added the user with password.

If it that the $Link is looking for a database in the folder in which the PHP script is run from?

All help will be very much appreciated.

Thanks
Hamish
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP
hamish is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 11-11-2004, 12:51 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Try this:

mysql_connect("$host","$user","$password")

Steve.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 01:02 PM
Skilled Talker

Posts: 79
hey,

no luck with that, I'm afraid.

Hamish
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP
hamish is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 01:25 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
You have not selected a database, try the following:

//set variables
$host = "localhost";
$user = "hc_books_user";
$password = "password";
$dbname = "hc_books";
$tablename = "books";

$Link = mysql_connect("$host","$user","$password")
or die(mysql_error());
mysql_select_db("$dbname",$Link)
or die(mysql_error());

$Query = "INSERT into $tablename values ('0', '$author', '$title', '$year', '$genre')";
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 01:30 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
It would seem to me that your php.ini file is not set up correctly to allow mysql. Which version of PHP are you using? My guess is PHP5.

Also, if its not too much of a hassle could you post your php.ini file inside code tags?
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 01:43 PM
Skilled Talker

Posts: 79
hey

here is the mySQL part of the php.ini file

Code:
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent).  -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect().  If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysql.default_port = 

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =

; Maximum time (in secondes) for connect timeout. -1 means no limimt
mysql.connect_timeout = 60

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Erros will be displayed.
mysql.trace_mode = Off
Hope this helps.

Running PHP 4.3.8. and mySQL 4.0.21.

Gaffer Sports, my next line : $Result = mysql_db_query ($dbname, $Query, $Link); brings up the database name. The method is fine, as I have tried it on a databse which I know to be working.

THanks guys,
Hamish
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP

Last edited by hamish : 11-11-2004 at 01:52 PM.
hamish is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 02:19 PM
Skilled Talker

Posts: 79
Hello,

I have found this site: http://uk.php.net/mysql which says that I need to compile PHP with mySQL support. Is there anyway to update the PHP config file to point it to the mySQL database directory, or do I have to reinstall?

Hamish
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP
hamish is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 02:46 PM
Skilled Talker

Posts: 79
OK, I found out that my PHP was not installed iwth mySQL support.

I did phpinfo and found the line '--without-mysql' in the Configure Command. Does anyone know if I have to install the whole thing again?

Hamish
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP
hamish is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 02:53 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Not sure, I used all in one installers.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 03:11 PM
Skilled Talker

Posts: 79
I'm trying to reinstall now, with mySQL support. Maybe it will work. Hope so.

hamish
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP
hamish is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 06:51 PM
Skilled Talker

Posts: 79
Hello
It is now working. Problem as no mySQL support in PHP.

Thanks for all your help.

H
__________________
http://www.iskm.com/backup/ secure and fully automated computer data backup for small and medium sized companies.

FREE OFFSITE BACKUP
hamish is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to "Call to undefined function" error. Do I need to link my webpage to a database?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.45752 seconds with 12 queries