i connect to my database[php]
$cxn = mysql_connect (host, user, passwd, name) or die (“not good”. mysql_error())
$query = “SELECT * FROM primary” ;
$result = mysql_query ($query, $cxn) or die
[/php]
althou i left them out i do have semi colons at end of lines the error is this it tells me that $cxn is not a resource and so it dies anyone have an idea on what causes this??? i am using xp and wamp
All you did was open a connection to the db server. you need to actually select which database you want to use though (mysql_db_select() i think it is). then you can run that query.
You declare $cxn in this line:
$cxn = mysql_connect (host, user, passwd, name) or die (“not good”. mysql_error())
This will not work. First, you are not giving the connection info to MySQL.
Should be something like:
$host = “www.mydomain.com”;
$user = “myusername”;
$passwd = “mypassword”;
$cxn = mysql_connect ($host, $user, $passwd) or die (“not good”. mysql_error());
You have to fill in your information about your MySQL server into the variables and then you will get a connection made.
Here is a tutorial on how it should work:
http://www.tizag.com/mysqlTutorial/mysqlconnection.php
(press continue to see how to use the connection…)
Hope that helps! Good luck!
Hii deniss,
//
lets assume that your database connect info is as follow:
$host = “localhost”;
$user = “root”;
$passwd = “secret”;
$db = “mydatabase”;
$conn = mysql_connect ($host, $user, $passwd) or die (“could not connect to the databse”. mysql_error())
//before you run a query you must select the databse name
//this select the databse
mysql_select_db($db);
$query = “SELECT * FROM primary” ;
//now run the query
$result = mysql_query ($query) or die(“erorr in query”);
//check if query was sucessful
if ($result)
{
echo “sucessfuly message”;
}
else
{
echo “eorrr”;
}
if you have any question just pm me
I figured the name, host, etc was just fill-ins, but yea that would make a difference
LOL, Richei, ever play “64 questions” but only get the first 3? 3 lines of code is a puzzle by itself… LOL