CREATE DATABASE name' from config.php

This is a discussion on "CREATE DATABASE name' from config.php" within the PHP Forum section. This forum, and the thread "CREATE DATABASE name' from config.php are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 21st, 2007, 16:53
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,296
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
CREATE DATABASE name' from config.php

i am having a little problem, i want to define the CREATE DATABASE 'name' inside the config.php, - i am going to build an install an hopefully have a form to be filled out to create all the config.php stuff after submission

PHP: Select all

<?php include 'config.php';?>
<?php
$conn 
mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
$db  'CREATE DATABASE saltyblog';
mysql_select_db($db);
$result mysql_query($db);
$sql mysql_select_db('saltyblog') or die('Cannot select database');
// Create a MySQL table in the selected database
       
$sql="CREATE TABLE form (
        title TEXT NOT NULL,
        date VARCHAR(25) NOT NULL, 
        subject VARCHAR(30) NOT NULL, 
        blog_mes TEXT NOT NULL ) "
;
   
  
mysql_query($sql) or die (mysql_error());

mysql_close($conn);
?>
thank you ( please see attached image )
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Jan 19th, 2008 at 19:57.
Reply With Quote

  #2 (permalink)  
Old Sep 21st, 2007, 16:55
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CREATE DATABASE name' from config.php

Replace this

PHP: Select all

$db  'CREATE DATABASE saltyblog'
with this

PHP: Select all

$db  'CREATE DATABASE '.$dbname
Reply With Quote
  #3 (permalink)  
Old Sep 21st, 2007, 17:03
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,296
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: CREATE DATABASE name' from config.php

thats what i did, but the database created a database literly called $dbname, or is the dot important ?
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #4 (permalink)  
Old Sep 21st, 2007, 17:18
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,296
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: CREATE DATABASE name' from config.php

hold on, i think this is the problem now
PHP: Select all

$sql mysql_select_db('.$dbname') or die('Cannot select database'); 

__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Sep 21st, 2007 at 17:30.
Reply With Quote
  #5 (permalink)  
Old Sep 21st, 2007, 17:18
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: CREATE DATABASE name' from config.php

uh try
$db = "CREATE DATABASE '$dbname'";
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Sep 21st, 2007, 17:23
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CREATE DATABASE name' from config.php

Quote:
Originally Posted by alexgeek View Post
uh try
$db = "CREATE DATABASE '$dbname'";
No ... you need the . to tack on a variable

The code I posted above should work
PHP: Select all

$db  'CREATE DATABASE '.$dbname
Makesure you put it AS IS!
Reply With Quote
  #7 (permalink)  
Old Sep 21st, 2007, 17:23
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,296
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: CREATE DATABASE name' from config.php

database created i just cant select it now

tryed
PHP: Select all

$sql mysql_select_db('.$dbname') or die('Cannot select database'); 

but its not working
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Sep 21st, 2007 at 17:30.
Reply With Quote
  #8 (permalink)  
Old Sep 21st, 2007, 17:47
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: CREATE DATABASE name' from config.php

dont think you need a . here:
('.$dbname')

try
('$dbname')
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Sep 21st, 2007, 17:59
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CREATE DATABASE name' from config.php

No .... the . is to attach a multiple variables together or to text... like

PHP: Select all

$name $firstname.$lastname
if you wanted a space in between you would do
PHP: Select all

$name $firstname.' '.$lastname
Then you could do
PHP: Select all

echo 'My name is '.$name
When you are just referencing variables like you did just above, you don't put the .

hth
Reply With Quote
  #10 (permalink)  
Old Sep 21st, 2007, 18:34
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,296
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: CREATE DATABASE name' from config.php

done

PHP: Select all

<?php include 'config.php';?>
<?php
$conn 
mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
$db  'CREATE DATABASE '.$dbname;
mysql_select_db($db);
$result mysql_query($db);
 
$db mysql_select_db($dbname) or die('Cannot select database');
// Create a MySQL table in the selected database
       
$db="CREATE TABLE form (
        title TEXT NOT NULL,
        date VARCHAR(25) NOT NULL, 
        subject VARCHAR(30) NOT NULL, 
        blog_mes TEXT NOT NULL ) "
;
   
  
mysql_query($db) or die (mysql_error());
mysql_close($conn);
?>
thank you for pointing me in the right direction
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #11 (permalink)  
Old Sep 21st, 2007, 18:41
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CREATE DATABASE name' from config.php

No problem!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] php re-writing variables in config from form Emzi PHP Forum 2 Jan 22nd, 2008 07:58
[SOLVED] writing a config file saltedm8 PHP Forum 2 Oct 13th, 2007 18:31
can create database but not tables saltedm8 Databases 28 Sep 16th, 2007 19:31
config.xml klimi73 Other Programming Languages 0 Nov 13th, 2005 06:30
newbie simple create database to record web page input jfb130 Databases 3 Aug 28th, 2005 16:37


All times are GMT. The time now is 02:05.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43