# Help write a Very Simple Code that keeps giving me errors

**URL:** <https://www.phphelp.com/t/help-write-a-very-simple-code-that-keeps-giving-me-errors/15854>\
**Category:** Code Snippets\
**Created:** [February 9, 2012, 5:11am UTC](https://www.phphelp.com/t/help-write-a-very-simple-code-that-keeps-giving-me-errors/15854 "2012-02-09T05:11:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![infektid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/i/53a042/32.png) [@infektid](https://www.phphelp.com/u/infektid)\
**Post date:** [February 9, 2012, 5:11am UTC](https://www.phphelp.com/t/help-write-a-very-simple-code-that-keeps-giving-me-errors/15854/1 "2012-02-09T05:11:51Z")

</div>

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 $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

# 
Form Input Data

| Form Input Employees Data |
| 

| Part Number: | |
| Part Name: | |
| Shelf Number: | |
| Bin Number: | |
| Cost: | |
| Stock Amount: | |
| Amount In Stock: | |
| Machine/Model: | |
| | |

 |

#

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:

> **[40797206.jpg - Click to see more photos](http://imageshack.com/f/el40797206j)**
>
> Store and share all of your images @ IMAGESHACK.com

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

---

<div class="post-metadata">

**Author:** ![sarthakpatel](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@sarthakpatel](https://www.phphelp.com/u/sarthakpatel)\
**Post date:** [February 21, 2012, 1:28pm UTC](https://www.phphelp.com/t/help-write-a-very-simple-code-that-keeps-giving-me-errors/15854/2 "2012-02-21T13:28:19Z")

</div>

> Hello infektid, please do the below changes in your code.
> 
> [php]  
> Replace your query  
> $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]’)”;
> 
> //use this code instead of above code
> 
> $partnum = $\_POST[‘partnum’];  
> $partname = $\_POST[‘partname’];  
> $shelf = $\_POST[‘shelf’];  
> $bin = $\_POST[‘bin’];  
> $instock = $\_POST[‘instock’];  
> $order = $\_POST[‘order’];  
> $machine = $\_POST[‘machine’];  
> //NOTE: if any of the field is define as integer than remove single quote
> 
> # here i am thinking that partnum is define as integer so did not use single quotes. if there is more fields are integer than also remove single quotes form below query.
> 
> $sql=“INSERT INTO test (partnum, partname, shelf, bin, instock, order, machine) VALUES ($partnum ,‘$partname’,‘$shelf’,‘$bin’,‘$instock’,‘$order’,‘$machine’)”;
> 
> [/php]
> 
> I hope this will helpful for you.  
> Reply your feedback  
> ~~SR~~

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [May 3, 2012, 4:42pm UTC](https://www.phphelp.com/t/help-write-a-very-simple-code-that-keeps-giving-me-errors/15854/3 "2012-05-03T16:42:43Z")

</div>

Simpler way without creating more variables…  
Notice the {}. This is also better because it will always be obvious where your data is coming from.

[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]

---

<div class="post-metadata">

**Author:** ![Gears](https://www.phphelp.com/user_avatar/www.phphelp.com/gears/32/259_2.png) [@Gears](https://www.phphelp.com/u/Gears)\
**Post date:** [June 14, 2012, 12:22am UTC](https://www.phphelp.com/t/help-write-a-very-simple-code-that-keeps-giving-me-errors/15854/4 "2012-06-14T00:22:00Z")

</div>

use {}  
always the best way to make sure only “data” and not “commands” get used.
