Help write a Very Simple Code that keeps giving me errors

I need help with a Very simple code for my job and i just can not get it to work i dont know very much about php but i’m trying?!?

Ok, i would like someone to write the php code for me or fix what i have to work right.


Here is the Error I am Getting:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order, machine) 

This is my INPUT.PHP

[php]<?php
$con = mysql_connect(“localhost”,“MyUsername”,“MYPASSWORD”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“MY DATABASE”, $con);

$sql=“INSERT INTO test (partnum, partname, shelf, bin, instock, order, machine)
VALUES
(’$_POST[partnum]’,’$_POST[partname]’,’$_POST[shelf]’,’$_POST[bin]’,’$_POST[instock]’,’$_POST[order]’,’$_POST[machine]’)”;

if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}
echo “You Have Suceccfully Added a New Part”;

mysql_close($con)
?>[/php]

HERE IS MY FORM PAGE

[php]

Form Input Data
Form Input Employees Data
Part Number:
Part Name:
Shelf Number:
Bin Number:
Cost:
Stock Amount:
Amount In Stock:
Machine/Model:
[/php]

basically what i want is a simple code that will input a part number, part name, Shelf number, Bin Number, Cost, Stock Amount, Amount In Stock, Machine/model that is goes to on a searchable display page

So far this is what i have:

http://imageshack.us/photo/my-images/525/40797206.jpg/

i need a search and a way to edit each of them so i can remove the table or edit the info on a certain table and add info

Thanks

[php]
$sql=“INSERT INTO test (partnum, partname, shelf, bin, instock, order, machine)
VALUES
(’$_POST[partnum]’,’$_POST[partname]’,’$_POST[shelf]’,’$_POST[bin]’,’$_POST[instock]’,’$_POST[order]’,’$_POST[machine]’)”;

[/php]

try changing to:

[php]

$sql=“INSERT INTO test (partnum, partname, shelf, bin, instock, order, machine)
VALUES
(’{$_POST[‘partnum’]}’,’{$_POST[‘partname’]}’,’{$_POST[‘shelf’]}’,’{$_POST[‘bin’]}’,’{$_POST[‘instock’]}’,’{$_POST[‘order’]}’,’{$_POST[‘machine’]}’)”;
[/php]

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order, machine) VALUES

This is what i get it but if i remove ORDER and MACHINE or just remove TWO ITEMS it works? Any Idea?

Hmm the next thing I could think of is using single quotations on the items in the parenthesis:
[php]
$sql=“INSERT INTO test (partnum, partname, shelf, bin, instock, order, machine)
VALUES
(’{$_POST[‘partnum’]}’,’{$_POST[‘partname’]}’,’{$_POST[‘shelf’]}’,’{$_POST[‘bin’]}’,’{$_POST[‘instock’]}’,’{$_POST[‘order’]}’,’{$_POST[‘machine’]}’)”;

I am thinking maybe your box is treating the word “order” as the php command, rather than a table name, so maybe putting it in the single slanted quotation might solve your error

[/php]

It’s a mysql statement, not php. But you are corrrect :slight_smile:

LOL… :smiley: yeah mysl command :smiley: you know what I mean :smiley: I am glad that fixed your problem!! so can we mark this topic as solved? :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service