?
Solved

Displaying output of success or failure of creating a database

Posted on 2007-07-28
3
Medium Priority
?
303 Views
Last Modified: 2013-12-12
Hi guys!
Im a total newbie to PHP so please bare with me.

I have the following php script (create.php) that creates a database called test001 in mysql.

When I launch this in a web browser:
http://localhost/create.php
I dont get anything on the page, just blank, but if I go into mysql, the new database has been created.

What Id like to learn how to do, is to put in:
An if statement to test success and failure of creating the database, and display this on the web page.

Any help greatly appreciated. Here is my script:

============================
<?php
include 'config.php';
include 'opendb.php';

$query  = "CREATE DATABASE test001";
$result = mysql_query($query);

include 'closedb.php';
?>
=============================================
0
Comment
Question by:Simon336697
3 Comments
 
LVL 28

Assisted Solution

by:gamebits
gamebits earned 960 total points
ID: 19585224
<?php
include 'config.php';
include 'opendb.php';

$query  = "CREATE DATABASE test001";
$result = mysql_query($query);

$good = mysql_numrow($result);

if($good > 0){echo "Database has been created";}

include 'closedb.php';
?>
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1040 total points
ID: 19585229
<?php
include 'config.php';
include 'opendb.php';

$query  = "CREATE DATABASE test001";
mysql_query($query);
$result = mysql_error();

if ($result == "")
{
  echo "Creation of database succeeded!";
}
else
{
  echo "Creation of database failed: $result";
}


include 'closedb.php';
?>
0
 
LVL 1

Author Comment

by:Simon336697
ID: 19585255
Thanks so much guys to both of you for your really fast and great responses!
Appreciate it, just tried out both, and both work.
Thanku :>)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question