PDA

View Full Version : Silly msql error.



Excellent
11-07-2008, 11:40 PM
Hey guys, just got onto coding something and I get this silly mysql error which I've never even heard of.

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/blah/public_html/thing/testing.php on line 4

This is my code.

<?php
session_start();
$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("db", "$connect") or die(mysql_error());
?>Now as you can see line 4 is just selecting my database, any clues? +REP.

Also I've checked my tables to make sure nothing numerical is there, all fine.

Moved by Invent (Forum Moderator) from Design & Development: Please post in the correct forum next time, thanks :).

Independent
11-07-2008, 11:49 PM
Hey guys, just got onto coding something and I get this silly mysql error which I've never even heard of.

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/blah/public_html/thing/testing.php on line 4

This is my code.

<?php
session_start();
$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("db", "$connect") or die(mysql_error());
?>Now as you can see line 4 is just selecting my database, any clues? +REP.

Also I've checked my tables to make sure nothing numerical is there, all fine.
Are you seriously stupid?

$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("db", "$connect") or die(mysql_error());

There's a clue.

Excellent
11-07-2008, 11:59 PM
Are you seriously stupid?

$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("db", "$connect") or die(mysql_error());

There's a clue.Are you seriously stupid? This doesn't even matter.

Independent
12-07-2008, 12:17 AM
Are you seriously stupid? This doesn't even matter.

$conn is being called for no reason, and $connect doesn't exist.

:eusa_clap

Own up to your mistake.. I am right, you are wrong.

So by the looks of it, I am better at php than you if you couldn't realize that.

Source
12-07-2008, 12:27 AM
//Connect to the mysql database
$conn = mysql_connect("localhost", "user", "password");

//Select DB using the correct connection variable.
mysql_select_db("db", $conn) or die(mysql_error());

I'm not sure on need the " around $conn... you don't even really need to define which connection to select the database if you only have that 1.

Independent
12-07-2008, 12:29 AM
//Connect to the mysql database
$conn = mysql_connect("localhost", "user", "password");

//Select DB using the correct connection variable.
mysql_select_db("db", $conn) or die(mysql_error());
There you go "Lucas" you needed a guide to connect to a database, flipping hell.. YOUR PROJECT IS GOING TO BE MASSIVE, MORE MASSIVE THAN MYSPACE OR BEBO OR ANY OTHER POPULAR WEBSITE! WOAH, LOVE IT MAN.

Source
12-07-2008, 12:30 AM
Independant. Leave off, everyone makes silly mistakes every now and then - because they think the problem is deeper than it actually lyes.

So leave it, and grow up a little bit.

Independent
12-07-2008, 12:31 AM
Independant. Leave off, everyone makes silly mistakes every now and then - because they think the problem is deeper than it actually lyes.

So leave it, and grow up a little bit.
Lol, "Lucas" seems to notice my mistakes and do the exact same.

Excellent
12-07-2008, 11:43 AM
$conn is being called for no reason, and $connect doesn't exist.

:eusa_clap

Own up to your mistake.. I am right, you are wrong.

So by the looks of it, I am better at php than you if you couldn't realize that.
Okay listen now, $conn is my function name. $connect is being used to connect to the database. Since when do $conn and $connect even come to comprehend the same word? Also why do you keep calling me "lucas" congratulations kiddy, you know my name? Oh btw stop thinking you're so brilliant because I fixed it already - nothing you said was suffice.

"OH OH U CANNOT CODE INDEPENDENT LOL U IZ CRAP U FAIL" :rolleyes:

@Matt: Originally I didn't wrap quotes around it but it doesn't really matter, don't get no syntax error.

Source
12-07-2008, 11:50 AM
Okay listen now, $conn is my function name. $connect is being used to connect to the database. Since when do $conn and $connect even come to comprehend the same word? Also why do you keep calling me "lucas" congratulations kiddy, you know my name? Oh btw stop thinking you're so brilliant because I fixed it already - nothing you said was suffice.

Listen calm down mate. He was replying on the code that he COULD see from what you posted. How are we meant to know about any functions etc... if you havn't listed or explained it. Don't be so narrow minded.

Excellent
12-07-2008, 12:00 PM
Listen calm down mate. He was replying on the code that he COULD see from what you posted. How are we meant to know about any functions etc... if you havn't listed or explained it. Don't be so narrow minded.Well unless you know absolutely nothing about php that wouldn't need to be explained.

Source
12-07-2008, 12:04 PM
Are you been serious? Im sorry but your are been completly narrow minded for no reason now. I'll take some time to comment your original code so you can see how we would interp it:




// You start the session, fair enough
session_start();

// You use THIS variable to connect to the mysql database
$conn = mysql_connect("localhost", "user", "password");

//You use this function to select the database
//HOWEVER what ever you put after the first , must
//normally be the connection name you want it to affect
//At this point we can ONLY see $conn and you call $connect
//which is no-where to be seen.
mysql_select_db("db", "$connect") or die(mysql_error());

//Can you see any functions been called there?

Invent
12-07-2008, 12:08 PM
Can I ask what the point of a function is ($connect) when that parameter is just used to identify the MySQL connection?

I understand if the $conn variable wasn't a line above and so you were using a function to identify the MySQL connection and return it. But there is absolutely no point when the code is a line above.

Also, I'm not even sure if you can use a function for that parameter! I haven't really researched the mysql_select_db function as it's a very simple one..

Source
12-07-2008, 12:09 PM
Exactly. He's got this mind-set that he is not wrong, just the php engine... At least thats what it seems like :P

NEW-START
12-07-2008, 12:15 PM
Exactly. He's got this mind-set that he is not wrong, just the php engine... At least thats what it seems like :P

I actually quite like you. What was your previous name, if any?

Excellent
12-07-2008, 12:17 PM
Just noticed what you was talking about as I was using $conn, should have called $conn instead of $connect, changed now. Worked before as it turns out I DID use numericals in my tables.

Sorry for any inconvenience, just didn't notice.

Source
12-07-2008, 12:18 PM
Always been GasFMatt, relativly a new kid on the block :P (Bad Expression I know)

And thank god you realized excellent - it's the only way you can learn is by finding out what was wrong yourself.

NEW-START
12-07-2008, 12:24 PM
Always been GasFMatt, relativly a new kid on the block :P (Bad Expression I know)

And thank god you realized excellent - it's the only way you can learn is by finding out what was wrong yourself.

Ahh rightio.

Oddsocks
13-07-2008, 05:03 AM
<?php
session_start();
$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("db",$conn) or die(mysql_error());
?>


Should be the fix, but you might not have the function installed or whatever, if you have php 5 i suggest you use PDO Class or MYSQLI

:)

Source
13-07-2008, 01:56 PM
Did you even read through the thread? It was fixed a page back.. nice of you to try and help though.

Excellent
13-07-2008, 06:41 PM
<?php
session_start();
$conn = mysql_connect("localhost", "user", "password");
mysql_select_db("db",$conn) or die(mysql_error());
?>
Should be the fix, but you might not have the function installed or whatever, if you have php 5 i suggest you use PDO Class or MYSQLI

:)Already fixed it, but thanks anyway :) Just goes to show all coders can mess up, even on calling functions :P

Want to hide these adverts? Register an account for free!