Jump to content

A MySQL-Link ERROR


Neptunus Maris

Recommended Posts

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/rdrvisio/public_html/install.php on line 18


Thats the problem I cant figure out.  Here is the line of code.  Scroll down and you'll find where I noted line 18. (NOTE: its only a part of a script)

<?php

//this will install and populate tables in your database
include "config.php";
connect();

//start with the subscribers

$installsubs = <<<HERE
CREATE TABLE `subscribers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`date_sub` datetime NOT NULL '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
);
HERE;
$result = mysql_query($installsubs, $dbconn) or die(mysql_error());    <----LINE 18
print "Subscriber table created!";

=====================================

I just cant figure it out at all...please help me.


Thank you in advance
Neptune
Link to comment
Share on other sites

i think the problem is that your connect() function (which i assume is in your included config.php) is not connecting to the database.  check to make sure the path to config.php is correct. your include statement assumes it is in the same directory, because you do not have a path shown there. Is it really in the same directory? Also, check to make sure the connection info in connect() is correct. Is the host, user name, password, and db name correct?  Do you have mysql_error()'s attached to those function calls to report an error in connection?
Link to comment
Share on other sites

The connect() is correct and the code within it o connect to te database.  The included file "config.php" is i the same directory.  But as for the mysql_error() function, i thought that was a automatic function that was already made within PHP, if not I didnt know you had to make it.  It's just that in the books Ive read it said it was a pre-defined function for PHP.

This is what my connect() looks like in my config.php.

[sub]function connect() { //connects the database
global $servername, $username, $password, $dbname;
$dbconn = mysql_connect($servername, $username, $password) or die(mysql_error());
$select = mysql_select_db($dbname, $dbconn) or die(mysql_error());
} //end connect[/sub]

Thanks
Neptune
Link to comment
Share on other sites

mysql_error() [i]is[/i] a built in function.

okay your problem is that your $dbconn in your function is a local variable, so your connection does not apply to the rest of your script.

you need to return the variable and instead of doing just connect(); in your main script, do like

$connection = connect();

and then use $connection in your mysql_query
Link to comment
Share on other sites

Yeah that doesnt work either and then when I took the $dbconn(or what you told me $connection) out of the mysql_query.  I got this the next time around:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned NOT NULL '0000-00-00 00:00:00', PRIMARY KEY (`id`) )' at line 5

thats on line 5 of install.php, here are the first 19 lines of install.php;:

<?php

//this will install and populate tables in your database
include "config.php";
connect();

//start with the subscribers

$installsubs = <<<HERE
CREATE TABLE `subscribers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`date_sub` datetime unsigned NOT NULL '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
);
HERE;
$result = mysql_query($installsubs) or die(mysql_error());
print "Subscriber table created!";

--------------------------
And this is my server info:

General server information:
Operating system Linux
Kernel version 2.6.17.1
Machine Type i686
Apache version 1.3.36 (Unix)
PERL version 5.8.7
Path to PERL /usr/bin/perl
Path to sendmail /usr/sbin/sendmail
Installed Perl Modules Click to View
PHP version 5.0.4
MySQL version 4.1.21-standard-log
cPanel Build 10.9.0-CURRENT 28
Theme cPanel X v2.5.0
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.