Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    19

    Unanswered: Creating Database But Confused So much

    PHP Code:
    $db_post=$_POST['db-s1'];

     if (
    is_null($db_post) && empty($db_post))
                 {
                    
    $db_set=1;
                }
                    if(!empty(
    $db_post) && (!$db_post==""))
                    {
                        
    $db_test=mysql_select_db($db_post);
                            if(!
    $db_test){
                                echo 
    "Database Not Exist";
                    }
                                else
                                {
                                    
    $db_set=0;
                                } 
    I have very serious issue i want that when the user submit the form

    if the $db_post empty then it set flag to 1

    if the $db_post is not empty if user wrote some value like db then it check whether the database exist then it set to flag 1.

    but if not exist the database it show database not exists let us create. and set flag to 1 so it create database.

    please help for this criteria

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so when you select the DB you need to check the mysql error to see if the command worked or reported a problem. the most likely faults are going to be either can't find the db or inadequate / no permisssions.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2013
    Posts
    1

    Arrow

    Here is a simple script for creating a database as shown below -
    Code:
     <?php
    $dbhost = 'localhost:3036';
    $dbuser = 'root';
    $dbpass = 'rootpassword';
    $con = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $con )
    {
      die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    $sql = 'CREATE Database test_db';
    $retval = mysql_query( $sql, $con );
    if(! $retval )
    {
      die('Could not create database: ' . mysql_error());
    }
    echo "Database test_db created successfully\n";
    mysql_close($con);
    ?>
    Use validation service as you tried above to verify whether given database name is exist or not - If it exists echo "Given database name exists", If not allow to create new database with that given name.

    For more details, just go here:
    http[:]//php[.]net/manual/en/function[.]mysql-create-db[.]php

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •