/    Sign up×
Community /Pin to ProfileBookmark

Whats wrong with my database table creation

I can not get this to work no matter what I do what am i doing wrong

[code=php]
$sqlCommand = “CREATE TABLE products (
id int(11) NOT NULL auto_increment,
product_name varchar(255) NOT NULL,
image_1 varchar(255) NULL,
image_2 varchar(255) NULL,
image_3 varchar(255) NULL,
image_4 varchar(255) NULL,
thumb_1 varchar(255) NULL
thumb_2 varchar(255) NULL,
thumb_3 varchar(255) NULL,
thumb_4 varchar(255) NULL,
price varchar(16) NOT NULL,
qty_available varchar(16) NOT NULL,
weight varchar(16) NOT NULL,
length varchar(16) NULL,
width varchar(16) NULL,
height varchar(16) NULL,
category varchar(255) NOT NULL,
sub_category varchar(255) NULL,
sub_sub_category varchar(255) NULL,
details text NOT NULL,
brief_details text NOT NULL,
extra_information text NULL,
special information text NULL,
date_added date NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY product_name (product_name)
) “;
if (mysql_query($sqlCommand)){
echo “Your products table has been created successfully!”;
} else {
echo “CRITICAL ERROR: products table has not been created.”;
}
?>[/code]

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 23.2011 — How about echoing mysql_error() in your else block to find out what MySQL is complaining about?
Copy linkTweet thisAlerts:
@NogDogJun 23.2011 — PS: One issue I see is it appears you have a column named "special information", which either needs to be quoted with back ticks or else have the space replaced with an underscore.
Copy linkTweet thisAlerts:
@shutterbugauthorJun 23.2011 — thanks I am trying the eorr reporting and i added the underscore It think Ive stared at it to long.
Copy linkTweet thisAlerts:
@shutterbugauthorJun 23.2011 — I did the error reporting it says No database selected however if I run a test to make sure it can connect I get the echo it connected so where could the problem lie any ideas.
Copy linkTweet thisAlerts:
@AlgieCaballesJun 23.2011 — Hi... maybe just a little comment.. i saw there an ending "?>", were there is no beginning "<?php".. and just try every field name put a single quote...
Copy linkTweet thisAlerts:
@AlgieCaballesJun 23.2011 — hi... in your "mysql_query($sqlCommand)".. try to add mysql_error() function in order to know the error... tnx.
Copy linkTweet thisAlerts:
@NogDogJun 23.2011 — I did the error reporting it says No database selected however if I run a test to make sure it can connect I get the echo it connected so where could the problem lie any ideas.[/QUOTE]


Did you do a mysql_select_db() after connecting?
Copy linkTweet thisAlerts:
@DasherJun 23.2011 — You might try phpMyAdmin as a tool to test out your database and related queries.
Copy linkTweet thisAlerts:
@shutterbugauthorJun 23.2011 — Thanks to all for the help
Copy linkTweet thisAlerts:
@shutterbugauthorJun 23.2011 — [code=php]
if (isset($_POST['Product_Name'])) {
$Image_1 = mysql_real_escape_string($_POST['thisID']);
$Image_2 = mysql_real_escape_string($_POST['thisID']);
$Image_3 = mysql_real_escape_string($_POST['thisID']);
$Image_4 = mysql_real_escape_string($_POST['thisID']);
$Product_Name = mysql_real_escape_string($_POST['Product_Name']);
$Price = mysql_real_escape_string($_POST['Price']);
$Qty_Available = mysql_real_escape_string($_POST['Qty_Available']);
$Weight = mysql_real_escape_string($_POST['Weight']);
$Length = mysql_real_escape_string($_POST['Length']);
$Width = mysql_real_escape_string($_POST['Width']);
$Height = mysql_real_escape_string($_POST['Height']);
$Category = mysql_real_escape_string($_POST['Category']);
$Sub_Category = mysql_real_escape_string($_POST['Sub_Category']);
$Sub_Sub_Category = mysql_real_escape_string($_POST['Sub_Sub_Category']);
$Details = mysql_real_escape_string($_POST['Details']);
$Brief_Details = mysql_real_escape_string($_POST['Brief_Details']);
$Extra_Information = mysql_real_escape_string($_POST['Extra_Information']);
$Special_Information = mysql_real_escape_string($_POST['Special_Information']);

// See if that product name is an identical match to another product in the system
$sql = mysql_query("UPDATE products SET Product_Name='$Product_Name', Price='$Price', Details='$Details', Qty_Available='$Qty_Available', Weight='$Weight', Length='$Length', Width='$Width', Height='Height', Category='Category', Sub_Categor'Sub_Category', Sub_Sub_Category='$Sub_Sub_Category', Details='$Details', Breif_Details='$Breif_Details', Extra_Infromation='$Extra_Infromation', Special_Information='$Special_Information' WHERE id='$pid'");

if ($_FILES['fileField']['tmp_name'] != "") {
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
}

exit();
}
?>
[/code]


Here are the erros I keep getting

Notice: Undefined index: Width in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 42

Notice: Undefined index: Category in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 44

Notice: Undefined index: Sub_Category in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 45

Notice: Undefined index: Sub_Sub_Category in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 46

Notice: Undefined index: Extra_Information in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 49

Notice: Undefined variable: Breif_Details in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 53

Notice: Undefined variable: Extra_Infromation in /hermes/web12b/b1765/pow.emmasgraphics/htdocs/Testing_Store_Setup/storeadmin/inventory_edit.php on line 53

I have double checked its all the same as the server so I don't know whats wrong
Copy linkTweet thisAlerts:
@skywalker2208Jun 23.2011 — You have some misspelled variables.
×

Success!

Help @shutterbug spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...