Page 1 of 1

MySQL_Query Issue

Posted: Sat Sep 22, 2012 9:55 pm
by PulpJuice
Firstly, I apologize for my newbness.

Alright, haha, so I've been hammering at some basic stuff and I'm just simply at a loss...

<?php
$con = mysql_connect("localhost", "X", "X");
$db = "X";
$conn = mysql_select_db($db, $con);
$sql = 'SELECT * FROM users';
$userlist = mysql_query($sql, $conn);
echo $userlist;
mysql_close($con);
?>

I get this

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/pulpjuic/public_html/learning/index.php on line 14

I realize there's a lot of junk, it's the result of brute force when tutorial examples produced the same problem as the warning or fatal errors, etc. Before I had issues with database select

Your help is appreciated :drunk:

Re: MySQL_Query Issue

Posted: Sun Sep 23, 2012 3:33 am
by requinix
mysql_select_db() only returns whether it was successful or not. It's not the MySQL connection resource that $con is.

Keep using $con and disregard $conn (except for telling whether the call was successful, of course).

Re: MySQL_Query Issue

Posted: Sun Sep 23, 2012 12:36 pm
by califdon
Requinix is precisely correct. But let me suggest that you take this initial opportunity for you to learn mysqli ("improved mysql") rather than mysql. If you first learn mysql, you will be tempted to not trouble to learn mysqli, and that would be a mistake. If you begin by learning mysqli, it will be no harder to learn than mysql, but mysqli is strongly recommended.

Re: MySQL_Query Issue

Posted: Mon Sep 24, 2012 9:03 pm
by PulpJuice
@Requinix
Thank you, that was extremely helpful :)

@Califdon
I will certainly look into that. Thank you for pointing me in the right direction (y)

Re: MySQL_Query Issue

Posted: Thu Sep 27, 2012 9:30 am
by temidayo
if you have a successful query, the following line

Code: Select all

echo $userlist;
will not work. You cannot just echo the result of a query!