Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell driver drivers email error ethernet excel firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition password problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
why isn't this script working


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
vipernet's Avatar
Senior Member with 109 posts.
 
Join Date: Aug 2007
04-Oct-2007, 02:12 PM #1
why isn't this script working
Working on a simple script to create a database using php with mysql server.

I get no connection errors, or creating DB errors, when i execute the script it just says done at the button of browers
Why doesn't this create the table?

PHP Code:
<?php
include 'config.php';
include 
'opendb.php';

$query  "CREATE DATABASE school";
$result mysql_query($query);

include 
'closedb.php';
?>
config.php
PHP Code:
<?php
// Connect to Database
$dbhost 'localhost';
$dbuser 'root';
$dbpass 'password';
$dbname 'DBname';

?>
opendb.php

PHP Code:
<?php
// open database
$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
closedb.php

PHP Code:
<?php
mysql_close
($conn);
?>
haswalt's Avatar
Computer Specs
Senior Member with 416 posts.
 
Join Date: Nov 2004
Location: South Coast, UK
Experience: Advanced
04-Oct-2007, 02:42 PM #2
I see oyu have followed the tutorial here to the letter:
http://www.php-mysql-tutorial.com/cr...e-with-php.php

:P

Are you sure you have priviledges to create a table. if you are on web hosting you usually are not allowed. try adding:

PHP Code:
$result mysql_query($query,$conn) or die(mysql_error()); 
in place of your current line to test this.

Are you sure you meant database as well not table?
__________________
LQD Internet Limited
We've just got better! With the launch of our new site we have SLASHED our prices and upped the offering. Check it out!

10% Discount for ALL Tech Support Guy Members
Simply use the promo code of "T3CHGUY" when ordering to recieve your 10% discount on all shared and reseller hosting packages.
vipernet's Avatar
Senior Member with 109 posts.
 
Join Date: Aug 2007
04-Oct-2007, 02:48 PM #3
Error
Access denied for user 'ancientc'@'localhost' to database 'school'

thats what the problem was bud, thanks allot.

SO does this mean i have to create and make all the tables using phpmyadmin or is there a way around it.

Goal is to be able to add tables using a forms post..etc
haswalt's Avatar
Computer Specs
Senior Member with 416 posts.
 
Join Date: Nov 2004
Location: South Coast, UK
Experience: Advanced
04-Oct-2007, 03:03 PM #4
no create a database first, say schooll via phpmyadmin.

Then use your script to create tables i that database not databases themselves.
vipernet's Avatar
Senior Member with 109 posts.
 
Join Date: Aug 2007
04-Oct-2007, 03:10 PM #5
I'm not sure what this error means "

I created a DB called dt08
now i'm getting an error "

Query was empty

Code:
PHP Code:

<?php
include 'config.php';
include 
'opendb.php';


$result mysql_query($query,$conn) or die(mysql_error()); 

mysql_select_db('dt08') or die('Cannot select database');

$query 'CREATE TABLE contact( '.
         
'cid INT NOT NULL AUTO_INCREMENT, '.
         
'cname VARCHAR(20) NOT NULL, '.
         
'cemail VARCHAR(50) NOT NULL, '.
         
'csubject VARCHAR(30) NOT NULL, '.
         
'cmessage TEXT NOT NULL, '.
         
'PRIMARY KEY(cid))';

$result mysql_query($query);

include 
'closedb.php';
?>
vipernet's Avatar
Senior Member with 109 posts.
 
Join Date: Aug 2007
04-Oct-2007, 03:15 PM #6
never mind figured that part out:

The "
$result = mysql_query($query,$conn) or die(mysql_error());
"
Wasn't needed becuase i had to take out the
$query = 'CREATE DATABASE school';
$result = mysql_query($query);
part becuase won't let me create a DB
haswalt's Avatar
Computer Specs
Senior Member with 416 posts.
 
Join Date: Nov 2004
Location: South Coast, UK
Experience: Advanced
04-Oct-2007, 03:42 PM #7
you all sorted now then?
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:14 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.