can create database but not tables

This is a discussion on "can create database but not tables" within the Databases section. This forum, and the thread "can create database but not tables are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 15th, 2007, 20:57
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
can create database but not tables

i am trying to create a database with tables via injection, but i am having problems, it will create the database, but not the tables, can you see what is wrong here , thank you

Code: Select all
<?
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db  = 'CREATE DATABASE saltyblog';
$result = mysql_query($db);
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` DATE NOT NULL, '
        . ' `subject` VARCHAR(30) NOT NULL, '
        . ' `blog message` TEXT NOT NULL'
        . ' )'; 
mysql_close($link);
?>
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote

  #2 (permalink)  
Old Sep 16th, 2007, 00:32
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: can create database but not tables

Quote:
Originally Posted by saltedm8 View Post
i am trying to create a database with tables via injection, but i am having problems, it will create the database, but not the tables, can you see what is wrong here , thank you

Code: Select all
<?
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db  = 'CREATE DATABASE saltyblog';
$result = mysql_query($db);
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` DATE NOT NULL, '
        . ' `subject` VARCHAR(30) NOT NULL, '
        . ' `blog message` TEXT NOT NULL'
        . ' )'; 
mysql_close($link);
?>
PHP: Select all

$sql "CREATE TABLE FORM (
        title TEXT NOT NULL,
        date DATE NOT NULL,
        subject VARCHAR(30) NOT NULL,
        blog message` TEXT NOT NULL
        )"

that's it i think
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Sep 16th, 2007, 00:34
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: can create database but not tables

and you have to query it:

PHP: Select all

mysql_query($sql); 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #4 (permalink)  
Old Sep 16th, 2007, 10:39
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: can create database but not tables

very weird, its still not working, i must be missing something somewhere, but i am getting no errors
Code: Select all
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db  = 'CREATE DATABASE saltyblog';
$result = mysql_query($db);
$sql = mysql_select_db('saltyblog') or die('Cannot select database');
// Create a MySQL table in the selected database
mysql_query($sql);  
    $sql='CREATE TABLE `form` (
        `title` TEXT NOT NULL 
        `date` VARCHAR(25) NOT NULL 
        `subject` VARCHAR(30) NOT NULL 
        `blog_mes` TEXT NOT NULL ) ;' 
 
 
?>
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Sep 16th, 2007 at 10:43.
Reply With Quote
  #5 (permalink)  
Old Sep 16th, 2007, 10:52
SuperMember

SuperMember
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: can create database but not tables

instead of

'CREATE TABLE `form` (

try

CREATE TABLE `form` (
Reply With Quote
  #6 (permalink)  
Old Sep 16th, 2007, 10:54
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: can create database but not tables

Parse error: parse error in c:\program files\easyphp1-8\www\new folder (2)\input.php on line 15
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #7 (permalink)  
Old Sep 16th, 2007, 11:18
SuperMember

SuperMember
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: can create database but not tables

line 15 I think is this

`blog_mes` TEXT NOT NULL ) ;'

TRY `blog_mes` TEXT NOT NULL );
Reply With Quote
  #8 (permalink)  
Old Sep 16th, 2007, 11:29
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: can create database but not tables

nope, still the same - i think line 15 is this
Code: Select all
    $sql=CREATE TABLE `form` (
- as soon as you took out the hyphen, i got the error, - before i was getting no errors, it was just not creating the tables
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #9 (permalink)  
Old Sep 16th, 2007, 11:43
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: can create database but not tables

you have an excessive amount of uneeded apostrophes
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #10 (permalink)  
Old Sep 16th, 2007, 11:48
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: can create database but not tables

so which do i need, and which dont i need ? , i took this the 'create table' bit straight from the database

i have tryed this

Code: Select all
mysql_query($sql);  
    $sql='CREATE TABLE form (
        title TEXT NOT NULL 
        date VARCHAR(25) NOT NULL 
        subject VARCHAR(30) NOT NULL 
        blog_mes TEXT NOT NULL ) ';
but still no luck
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Sep 16th, 2007 at 11:52.
Reply With Quote
  #11 (permalink)  
Old Sep 16th, 2007, 12:04
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: can create database but not tables

for one thing you need $sql to be before the query
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #12 (permalink)  
Old Sep 16th, 2007, 12:10
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: can create database but not tables

no error, but still no tables

Code: Select all
 $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);
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #13 (permalink)  
Old Sep 16th, 2007, 13:59
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: can create database but not tables

Quote:
Originally Posted by saltedm8 View Post
no error, but still no tables

Code: Select all
 $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);
no commas in there, try this one:

Code: Select all
 $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());
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #14 (permalink)  
Old Sep 16th, 2007, 15:57
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: can create database but not tables

that did it, thank you very much very
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #15 (permalink)  
Old Sep 16th, 2007, 15:58
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: can create database but not tables

you're welcome
you know how to put data aswell?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #16 (permalink)  
Old Sep 16th, 2007, 16:00
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: can create database but not tables

how to insert data you mean ?

this ?
SELECT * FROM `form` WHERE 1

or INSERT INTO ?
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #17 (permalink)  
Old Sep 16th, 2007, 16:04
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: can create database but not tables

Quote:
Originally Posted by saltedm8 View Post
how to insert data you mean ?

this ?
SELECT * FROM `form` WHERE 1

or INSERT INTO ?
that would be to select data,
and you don't need 'form' just form
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #18 (permalink)  
Old Sep 16th, 2007, 16:08
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: can create database but not tables

ok, how would i insert data to 'blog_mes' for example from a form
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Sep 16th, 2007 at 16:10.
Reply With Quote
  #19 (permalink)  
Old Sep 16th, 2007, 16: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: can create database but not tables

PHP: Select all

 $sql="insert into form (title, date, subject, blog_mes)
VALUES ($title, $date, $subject, $blog_mes)"
;
   
  
mysql_query($sql) or die (mysql_error()); 
Same as before
just change the query,
obviously you need to define $title, $date etc.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #20 (permalink)  
Old Sep 16th, 2007, 16:24
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: can create database but not tables

this is my form, if it helps - ,
Code: Select all
<?
if ($_POST['submit'];) {
  $blog = $_POST['saltyblog'];
  $title = $_POST['title'];
  $subject = $_POST['subject'];
  $blog_mes = $_POST['blog_mes'];
  $sql="insert into form (title, date, subject, blog_mes)
VALUES ($title, $date, $subject, $blog_mes)";
mysql_query($sql) or die (mysql_error());
}
?>
<div align="center">
  <form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
    <p><input name="title" type="text" value="TITLE" size="100">
    </p>
    <table width="600" height="39" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="270"><input name="date" type="text" value="DATE" size="45"></td>
        <td width="58">&nbsp;</td>
        <td width="136">
          <label></label>
          <div align="center"><strong>SUBJECT:</strong></div></td>
        <td width="136"><select name="DROP" id="DROP">
          <option>website design tips</option>
                        </select></td>
      </tr>
    </table>
    <label></label>
    <p>
      <textarea name="blog" cols="100" rows="15">BLOG MESSAGE</textarea>
        </p>
    <table width="632" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="494">&nbsp;</td>
        <td width="138"><div align="right">
          <input type="submit" name="submit" value="SUBMIT BLOG">
        </div></td>
      </tr>
    </table>
    </form>
</div>
</body>
</html>
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Sep 16th, 2007 at 16:28.
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] create 2 tables saltedm8 PHP Forum 4 Oct 8th, 2007 12:53
CREATE DATABASE name' from config.php saltedm8 PHP Forum 10 Sep 21st, 2007 18:41
Displaying MySQL database tables on a page vandiermen PHP Forum 3 Jun 30th, 2007 21:58
two tables in one database, different result ntgcmlfu Classic ASP 5 Apr 20th, 2006 23:59
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 05:08.