Author Topic: Help write a Very Simple Code that keeps giving me errors  (Read 435 times)

infektid

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Help write a Very Simple Code that keeps giving me errors
« on: February 09, 2012, 07:01:18 PM »
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:

Code: [Select]
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 Code: [Select]
<?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)
?>


HERE IS MY FORM PAGE

PHP Code: [Select]
<head>
<
title>Form Input Data</title>
</
head>

<
body>
<
table border="1">
  <
tr>
    <
td align="center">Form Input Employees Data</td>
  </
tr>
  <
tr>
    <
td>
      <
table>
        <
form method="post" action="input.php">
        <
tr>
          <
td>Part Number:</td>
          <
td><input type="text" name="partnum" size="20">
          </
td>
        </
tr>
        <
tr>
          <
td>Part Name:</td>
          <
td><input type="text" name="partname" size="40">
          </
td>
        </
tr>
        <
tr>
          <
td>Shelf Number:</td>
          <
td><input type="text" name="shelf" size="20">
          </
td>
        </
tr>
        <
tr>
          <
td>Bin Number:</td>
          <
td><input type="text" name="bin" size="20">
          </
td>
        </
tr>
        <
tr>
          <
td>Cost:</td>
          <
td><input type="text" name="instock" size="20">
          </
td>
        </
tr>
        <
tr>
          <
td>Stock Amount:</td>
          <
td><input type="text" name="stockamount" size="20">
          </
td>
        </
tr>
        <
tr>
          <
td>Amount In Stock:</td>
          <
td><input type="text" name="order" size="20">
          </
td>
        </
tr>
        <
tr>
          <
td>Machine/Model:</td>
          <
td><input type="text" name="machine" size="40">
          </
td>
        </
tr>        
        <
tr>
          <
td></td>
          <
td align="right"><input type="submit" 
          
name="submit" value="Sent"></td>
        </
tr>
        </
table>
      </
td>
    </
tr>
</
table>
</
body>
</
html>
</
body>
</
html>


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
« Last Edit: February 11, 2012, 06:52:41 AM by jSherz »

plintu

  • freelance programmer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 246
  • Karma: +5/-0
    • View Profile
    • plintu.com
Re: Help write a Very Simple Code that keeps giving me errors
« Reply #1 on: February 10, 2012, 12:06:49 AM »
PHP Code: [Select]

$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]')"
;



try changing to:


PHP Code: [Select]


$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']}')"
;
Find an affordable programmer, contact me :D

infektid

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Help write a Very Simple Code that keeps giving me errors
« Reply #2 on: February 10, 2012, 11:06:49 PM »
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?

plintu

  • freelance programmer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 246
  • Karma: +5/-0
    • View Profile
    • plintu.com
Re: Help write a Very Simple Code that keeps giving me errors
« Reply #3 on: February 12, 2012, 10:49:10 PM »
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 Code: [Select]

$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 commandrather than a table nameso maybe putting it in the single slanted quotation might solve your error 

Find an affordable programmer, contact me :D

Laffin

  • BCFH
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 112
  • Karma: +5/-0
    • View Profile
Re: Help write a Very Simple Code that keeps giving me errors
« Reply #4 on: February 13, 2012, 12:11:10 AM »
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

It's a mysql statement, not php. But you are corrrect :)

plintu

  • freelance programmer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 246
  • Karma: +5/-0
    • View Profile
    • plintu.com
Re: Help write a Very Simple Code that keeps giving me errors
« Reply #5 on: February 13, 2012, 12:53:18 AM »
It's a mysql statement, not php. But you are corrrect :)
LOL... :D yeah mysl command :D you know what I mean :D I am glad that fixed your problem!! so can we mark this topic as solved? ;)
Find an affordable programmer, contact me :D