...

View Full Version : database connectivity problem



mscoder
11-12-2012, 05:04 PM
I used the following code for inserting form data into "userinfo" table of "user" database.The database and table was created on xampp(phpmyadmin).But the page displayed "Error: No database selected".... why?pls help..


<?php
$con = mysql_connect("localhost","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("user",$con);

$sql="INSERT INTO userinfo(id,pass)
VALUES
('$_POST[UID]','$_POST[pass]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con);
?>

abduraooft
11-12-2012, 05:06 PM
Try
mysql_select_db("user",$con) or die(mysql_error());

alemcherry
11-13-2012, 01:49 PM
Wasn't that obvious? You have error checking everywhere, except on line where it select the db. The error message clearly says "Error: No database selected"

Should be a wrong database name or the user have no rights on database mentioned.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum