[SOLVED] create 2 tables

This is a discussion on "[SOLVED] create 2 tables" within the PHP Forum section. This forum, and the thread "[SOLVED] create 2 tables are both part of the Program Your Website category.



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

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 8th, 2007, 11:18
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,299
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
[SOLVED] create 2 tables

i am trying to create 2 tables, the first is my form, and the second is for my login script and then i want to insert data into the members table

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 ) "
;
 
  
$db="CREATE TABLE `members` (
        `id` int(4) NOT NULL auto_increment,
        `username` varchar(65) NOT NULL default '',
        `password` varchar(65) NOT NULL default '',
         PRIMARY KEY (`id`)
       ) TYPE=MyISAM AUTO_INCREMENT=2" 
;
 
    
$db="INSERT INTO `members` VALUES (1, 'myusername', 'mypassword')" ;
 
  
mysql_query($db) or die (mysql_error());
mysql_close($conn);
?>
the problems i am having are,
if i removed the insert into part, it will only create the members table, but if i leave it on, it wont create my database at all

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

Last edited by saltedm8; Oct 8th, 2007 at 11:23.

  #2 (permalink)  
Old Oct 8th, 2007, 12:06
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: create 2 tables

take the quotes away from the the table name

eg.
PHP: Select all

$db="INSERT INTO members VALUES (1, 'myusername', 'mypassword')" 
You only need the quotes when creating the table, not referencing it.

Hope that helps,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #3 (permalink)  
Old Oct 8th, 2007, 12:20
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,299
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: create 2 tables

tryed that before, that is where i get this

Quote:
Table 'saltyblog.members' doesn't exist
thats with this

PHP: Select all

<?php include 'config.php';?>
<?php
$conn 
mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
$db  'CREATE DATABASE '.$dbname;
$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 ) "
;
 
  
$db="CREATE TABLE `members` (
        `id` int(4) NOT NULL auto_increment,
        `username` varchar(65) NOT NULL default '',
        `password` varchar(65) NOT NULL default '',
         PRIMARY KEY (`id`)
       ) TYPE=MyISAM AUTO_INCREMENT=2" 
;
 
    
$db="INSERT INTO `members` VALUES (1, myusername, mypassword)" ;
 
  
mysql_query($db) or die (mysql_error());
mysql_close($conn);
?>
with that, its not creating any database
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Oct 8th, 2007 at 12:27.
  #4 (permalink)  
Old Oct 8th, 2007, 12:30
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: create 2 tables

Sorry mate, got a bit confused.

You don't need quotes around *any* table names, even when creating them. Have you tried that?

If you have, still get rid of the quotes and try closing the connection before running your insert query..

PHP: Select all



mysql_close
($conn);
$conn mysql_connect($dbhost$dbuser$dbpass) or die ('How many lives?');
mysql_select_db($dbname);

$db="INSERT INTO members VALUES (1, myusername, mypassword)" 
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #5 (permalink)  
Old Oct 8th, 2007, 12:53
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,299
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: create 2 tables

after a bit of messing around i finally managed it with this

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 ) "
;
  
  
$mem="CREATE TABLE members (
  id int(4) NOT NULL auto_increment,
        username varchar(65) NOT NULL default '',
       password varchar(65) NOT NULL default '',
        PRIMARY KEY (id)
      ) TYPE=MyISAM AUTO_INCREMENT=2 "
;
   
  
mysql_query($db) or die (mysql_error());
  
mysql_query($mem) or die (mysql_error());
  
mysql_query ("INSERT INTO `members` VALUES (1, 'saltedm8', 'alarm7')");
  
mysql_close($conn);
?>
thanks for your help
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Closed Thread

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 Creat tables in MySQL Emzi PHP Forum 4 Jan 21st, 2008 12:41
[SOLVED] Building a website with tables thewebkid Starting Out 13 Oct 25th, 2007 12:21
can create database but not tables saltedm8 Databases 28 Sep 16th, 2007 19:31
Tables or CSS? bee_bo Web Page Design 15 Jul 6th, 2006 08:32
Tables in CSS ??? j4mes_bond25 Web Page Design 2 May 25th, 2006 21:10


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


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