Page 1 of 1

Having trouble generating feedback

Posted: Mon Sep 21, 2009 11:02 am
by Spoooon
I made a script that creates a new database in mysql.

It creates the database just fine. However, it will not deliver the feedback that the data was created. Where did I go wrong? Thanks in advanced.

Here is the code for the index file.

Code: Select all

 
<?php
 
if (!isset($_REQUEST['database']))
 
    {
    include 'form.html.php';
    }
else 
    {
    $database = $_REQUEST['database'];
    $database = str_replace(" ","",$database);
    $database = strtolower($database);
    $output= htmlspecialchars($database, ENT_QUOTES, 'UTF-8');
    include 'dbgenerator.php';
    
    }
 
?>
 
Here is the code for the database generator

Code: Select all

 
<?php
 
$link = mysqli_connect('localhost', 'root', '**********');
if (!$link)
{
 $output = 'Unable to connect to the database server.';
 include 'output.html.php';
 exit();
}
 
 
$sql = 'CREATE DATABASE ' . $database;
mysqli_query($link, $sql);
if (!mysqli_query($link, $sql))
    {
    $output = 'Error creating ' . $database . ' database.';
    exit();
    } 
else
{
$output = $database . " successfully created.";
include 'output.html.php';
}
?>
 
Here is the code for the output file

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Output</title>
    <meta http-equiv="content-type"
        content="text/html; charset=utf-8"/>
    </head>
    <body>
    <p>
        <?php 
        echo $output; 
        ?>
    </p>
    
    </body>
</html>
 

Re: Having trouble generating feedback

Posted: Mon Sep 21, 2009 11:34 am
by cpetercarter
"mysqli_query()" runs the query and returns true on success or false on failure. Your code runs "mysqli_query" twice, in lines 14 and 15 of the database generator script. Try commenting out line 14.