Having trouble generating feedback

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Spoooon
Forum Newbie
Posts: 5
Joined: Mon Sep 14, 2009 6:15 pm

Having trouble generating feedback

Post 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>
 
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Having trouble generating feedback

Post 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.
Post Reply