database dosent exist

I self learned php and I’m still learning.
The system I’m making, I just want to display all the my sql records in php. i tried for so many times… :’( can anyone help. :slight_smile:
this is the code…my database name is abc.and for now it has 5 records.can anyone tell me what wrong with my code?it says the “database doesn’t exist”

[php]
$username="";
$password="";
$database=“abc”;

//connect to sever
$connect = mysql_connect(“localhost”,"","") or die(“sever doesn’t exist”);

//connect to database
mysql_select_db(“sd”) or die(“database doesn’t exist”);

//query the database
$query = mysql_query(“SELECT * FROM client WHERE ClientName = ‘Harry’”);
$num_rows = mysql_num_rows($query);

//fetch the results / convert the results in to a query

if($num_rows > 0)
{
while($row = mysql_fetch_assoc($query))
{
echo $row[‘ClientName’]."
".$row[‘Address’]."
".$row[‘Telephone’]."
".$row[‘Fax’]."
";
}
}
else{
echo “There’s no entries within this database yet”;
}
[/php]

hello pujamano , Generally this error occures when you did not create the database in on you server and still you are trying to access that database. For this once you check your phpmyadmin that it contain any database having "sd" name if not than create it.

you can create database using php too at run time. check below code

[php]
if (!mysql_select_db(‘sd’)) {
echo(“creating database!\n”);
mysql_query(‘CREATE DATABASE sd’);
mysql_select_db(‘sd’);
}

[/php]
i hope this will helpful for you.
SR

it says…
creating database!
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in E:\xampp\htdocs\SD\Forms\connect.php on line 21
Theres no entries within this database yet

[php]

$username="";
$password="";
$database=“sd”;

//connect to sever
$connect = mysql_connect(“localhost”,"","") or die(“sever doesn’t exist”);

//connect to database
//mysql_select_db(“sd”) or die(“database doesn’t exist”);

if (!mysql_select_db(‘sd’)) {
//i changed it to what you said, still the error comes and my database name is ‘sd’
echo(“creating database!\n”);
mysql_query(‘CREATE DATABASE sd’);
mysql_select_db(‘sd’);
}

//query the database
$query = mysql_query(“SELECT * FROM client WHERE ClientName = ‘Harry’”);
$num_rows = mysql_num_rows($query);

//fetch the results / convert the results in to a query

if($num_rows > 0)
{
while($row = mysql_fetch_assoc($query))
{
echo $row[‘ClientName’]."
".$row[‘Address’]."
".$row[‘Telephone’]."
".$row[‘Fax’]."
";
}
}
else{
echo “Theres no entries within this database yet”;
}
[/php]

hello pujamano, now create a table having name client in your "sd" database . and insert some record in it and run your code. this time you get result. one more thing your client contain those field your trying to display like id, ClientName,Address,Telephone and Fax

i hope this will helpful for you.
SR

hi Sarthak,

the database is already created.my database is sd and in it there is a table called client it has 5 records. still the the error is there… :’(
if i drop the table n recreate the table again…hmm… on to it now…

hello pujamano,
if you have alredy created database and you have client table with records and than before recreating just check the db and table name. may be there is some space to is added with database name by mistake.
So once confirm that you have created correct database with proper name as well as table too.

one more thing please use below detail for database connection.
$username=“root”;
$password="";
$connect = mysql_connect(“localhost”,$username,"") or die(“sever doesn’t exist”);

SR

Hi Sarthak,

Thanks it’s working now :smiley: think there was a space missing when creating the database. Thank you very much. :slight_smile:

hello pujamano,
it’s really nice to hear that your problem is finally resolve.
Post more issue get fast response.

Have nice day to you.

SR

Sponsor our Newsletter | Privacy Policy | Terms of Service