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";
Put a test on the result of mysql_select_db() and make sure it's working.
(PS: Modern PHP apps should really be using either the MySQLi or PDO extension to interface with MySQL.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
What is the error? (You can use mysql_error() there just like for any other db error.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks