Current location: Hot Scripts Forums » Programming Languages » PHP » error when creating database tables with php script


error when creating database tables with php script

Reply
  #1 (permalink)  
Old 07-15-03, 05:04 PM
spiroth10 spiroth10 is offline
New Member
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation error when creating database tables with php script

please help me! I have a script that works,but I get an error when creating the database tables.it gives me "error when creating table". the script is below names have been changed for security.please tell me why I get this error.

--------------
the script
--------------

<?php
// PHP/MYSQL page.
//MySQL Variables.
require "function.php";
MySQL_connect("localhost","fake","fake","fake_db") ;
//Variables of Form
$id = $_POST['id'];
$name = $_POST['fname'];
$description = $_POST['description'];
$minpow = $_POST['minpow'];
$order = $_POST['order'];

//Connecting to MYSQL
MySQL_connect("localhost","fake","fake");

$sql=mysql_query("INSERT INTO forums ($id,$fname,$description,$minpow,$minpow,$minpow,0 ,0, , ,$order)");
$result = mysql_query($sql);

if ($result) {
echo("Table created successfully");
} else {
echo("error when creating table");
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-15-03, 05:07 PM
BdSBB BdSBB is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Georgetown, TX
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
$sql=mysql_query("INSERT INTO forums ($id,$fname,$description,$minpow,$minpow,$minpow,0
,0, , ,$order)"); // This is your problem right here
$result = mysql_query($sql);

Your $sql string has mysql_query() already outputting.
__________________
-- BdSBB
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-15-03, 05:21 PM
spiroth10 spiroth10 is offline
New Member
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
uhh what do I change it to?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-15-03, 05:30 PM
playtothebeat playtothebeat is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
i think you need to get rid of $result

your $sql is ALREADY runnig mysql_query


if you want to keep $sql and $result, then do this:

$result="INSERT into forums (all your stuff here)";
$sql=mysql_query($result)

by the way, when you insert into table, raen't you supposed to do

insert into forum VALUES('first','second') etc? you're supposed to have the VALUES() arent you?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 01-06-04, 04:59 PM
HasansWeb HasansWeb is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
playtothebeat, there are two ways. One in which you can define which row and then use VALUE to add to each (in order). In the other, you don't specify columns but you must specify a value for every single one (use NULL to skip).

But yeah, according to the manual and other references I've read, you use VALUE. That's a part of your problem.

$query = "INSERT INTO forums VALUES($id,$fname,$description,$minpow,$minpow,$mi npow,0 ,0, , ,$order)";
$result = mysql_query($query);

That's how I always do it. It should work fine...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP script required Mickey Job Offers & Assistance 8 09-07-03 04:00 PM
I need help with my first php script NeverMind PHP 4 08-01-03 02:27 PM
PHP script: authorize/contact database/form beavis Script Requests 1 07-22-03 09:15 PM
30% off Hosting - Free PHP Script Autoinstaller cyberwisdom General Advertisements 0 07-06-03 02:47 PM
script that measures height of tables and vertically aligns nested tables amj01 Script Requests 1 07-04-03 02:20 PM


All times are GMT -5. The time now is 01:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.