Jump to content

whats this error?


aebstract

Recommended Posts

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 'DESC,LOC,PRICE,SPARE)VALUES ('BPRS2-INS-1000', 'MEYN', 'INSPECTOR PUSHBUTTON STA' at line 1

 


<?php
session_start();
header("Cache-control: private");

if (isset ($_POST['submit'])) {
$problem = FALSE;


if (!$problem) {

$pn  = $_POST['pn'];
$mchn  = $_POST['mchn'];
$desc  = $_POST['desc'];
$loc  = $_POST['loc'];
$price  = $_POST['price'];
$spare  = $_POST['spare'];



$result = MYSQL_QUERY("INSERT INTO parts (PN,MCHN,DESC,LOC,PRICE,SPARE)".
"VALUES ('$pn', '$mchn', '$desc', '$loc', '$price', '$spare')") or die (mysql_error());


                      header("Location: newparts.php");

} else {
$content .= "$error";
}
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>setup account</title>

</head>

<body>








<?php
$content .= '<form action="newparts.php" method="post">
<br />
PN: <br /><input type="text" maxlength="100" class="textfield" name="pn" size="40" value="' . $_POST[pn] . '" /><br /><br />
MCHN: <br /><input type="text" maxlength="100" class="textfield" name="mchn" size="40" value="' . $_POST[mchn] . '" /><br /><br />
DESC: <br /><input type="text" maxlength="100" class="textfield" name="desc" size="40" value="' . $_POST[desc] . '" /><br /><br />
LOC: <br /><input type="text" maxlength="100" class="textfield" name="loc" size="40" value="' . $_POST[loc] . '" /><br /><br />
PRICE: <br /><input type="text" maxlength="100" class="textfield" name="price" size="40" value="' . $_POST[price] . '" /><br /><br />
SPARE: <br /><input type="text" maxlength="100" class="textfield" name="spare" size="40" value="' . $_POST[spare] . '" /><br /><br />



<input type="submit" name="submit" value="submit" class="textfield" /></form>';



echo "$content";
?>




</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/
Share on other sites

Cause this script isn't a public thing, it's just something I'm using to make life easier for myself for a short amount of time while I am doing some data entry. I know what I'm entering. The db is in the same order (not all columns are listed, but it skips through if you don't list, right?)

 

  id 

PN

TPN

MCHN

DESC

LOC

PRICE

SUB

SPARE

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483796
Share on other sites

<?php session_start();

header("Cache-control: private");

if (isset($_POST['submit'])) {
$problem = FALSE;

if (!$problem) {

$pn=mysql_real_escape_string($_POST['pn']);
$mchn=mysql_real_escape_string($_POST['mchn']);
$desc=mysql_real_escape_string($_POST['desc']);
$loc=mysql_real_escape_string($_POST['loc']);
$price=mysql_real_escape_string($_POST['price']);
$spare=mysql_real_escape_string($_POST['spare']);

$sql = "INSERT INTO parts(PN,MCHN,DESC,LOC,PRICE,SPARE) VALUES ('$pn', '$mchn', '$desc',
'$loc', '$price', '$spare')"; 

$result="mysql_query($sql)or die (mysql_error())";

header("Location: newparts.php");

} else {
$content .= "$error";
}
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>setup account</title>

</head>

<body>


<?php
$content .= '<form action="newparts.php" method="post">
<br />
PN: <br /><input type="text" maxlength="100" class="textfield" name="pn" size="40" value="' . $_POST[pn] . '" /><br /><br />
MCHN: <br /><input type="text" maxlength="100" class="textfield" name="mchn" size="40" value="' . $_POST[mchn] . '" /><br /><br />
DESC: <br /><input type="text" maxlength="100" class="textfield" name="desc" size="40" value="' . $_POST[desc] . '" /><br /><br />
LOC: <br /><input type="text" maxlength="100" class="textfield" name="loc" size="40" value="' . $_POST[loc] . '" /><br /><br />
PRICE: <br /><input type="text" maxlength="100" class="textfield" name="price" size="40" value="' . $_POST[price] . '" /><br /><br />
SPARE: <br /><input type="text" maxlength="100" class="textfield" name="spare" size="40" value="' . $_POST[spare] . '" /><br /><br />



<input type="submit" name="submit" value="submit" class="textfield" /></form>';



echo "$content";
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483797
Share on other sites

i done your insert correctly my way and added mysql_real_escape__string correct m8

 

<?php session_start();

header("Cache-control: private");

if (isset($_POST['submit'])) {
$problem = FALSE;

if (!$problem) {

$pn=mysql_real_escape_string($_POST['pn']);
$mchn=mysql_real_escape_string($_POST['mchn']);
$desc=mysql_real_escape_string($_POST['desc']);
$loc=mysql_real_escape_string($_POST['loc']);
$price=mysql_real_escape_string($_POST['price']);
$spare=mysql_real_escape_string($_POST['spare']);

$sql = "INSERT INTO parts(PN,MCHN,DESC,LOC,PRICE,SPARE) VALUES ('$pn', '$mchn', '$desc',
'$loc', '$price', '$spare')"; 

$result="mysql_query($sql)or die (mysql_error())";

header("Location: newparts.php");

} else {
$content .= "$error";
}
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>setup account</title>

</head>

<body>


<?php
$content .= '<form action="newparts.php" method="post">
<br />
PN: <br /><input type="text" maxlength="100" class="textfield" name="pn" size="40" value="' . $_POST[pn] . '" /><br /><br />
MCHN: <br /><input type="text" maxlength="100" class="textfield" name="mchn" size="40" value="' . $_POST[mchn] . '" /><br /><br />
DESC: <br /><input type="text" maxlength="100" class="textfield" name="desc" size="40" value="' . $_POST[desc] . '" /><br /><br />
LOC: <br /><input type="text" maxlength="100" class="textfield" name="loc" size="40" value="' . $_POST[loc] . '" /><br /><br />
PRICE: <br /><input type="text" maxlength="100" class="textfield" name="price" size="40" value="' . $_POST[price] . '" /><br /><br />
SPARE: <br /><input type="text" maxlength="100" class="textfield" name="spare" size="40" value="' . $_POST[spare] . '" /><br /><br />



<input type="submit" name="submit" value="submit" class="textfield" /></form>';



echo "$content";
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483802
Share on other sites

 

it your form there nothink wrong with my code!

 

what the header for going back to a page your posting to

<?php
$content .= '<form action="newparts.php" method="post">
<br />
PN: <br /><input type="text" maxlength="100" class="textfield" name="pn" size="40" /><br /><br />
MCHN: <br /><input type="text" maxlength="100" class="textfield" name="mchn" size="40" /><br /><br />
DESC: <br /><input type="text" maxlength="100" class="textfield" name="desc" size="40" /><br /><br />
LOC: <br /><input type="text" maxlength="100" class="textfield" name="loc" size="40"  /><br /><br />
PRICE: <br /><input type="text" maxlength="100" class="textfield" name="price" size="40" /><br /><br />
SPARE: <br /><input type="text" maxlength="100" class="textfield" name="spare" size="40" /><br /><br />



<input type="submit" name="submit" value="submit" class="textfield" /></form>';



echo "$content";
?>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483813
Share on other sites

Hmm.. I tried to echo it out but I'm just getting that error, don't know how to get around that. I took the mysql error off the end and all it does is reload the page with the values in the form fields.

 

redarrow: I want it to go back to the same page, so I can keep doing this over and over. There will be hundreds of parts, I don't want to take a lot of time, I would rather go back to my form and keep submitting parts.

 

I've tried a few different things, changing the query in terms of how I ran it and it seems to get stuck on DESC like the error says, anyone know how to get past that?

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483815
Share on other sites

use this form

 

<?php

$content .= "<form action='newparts.php' method='POST'>
<br />
PN: <br /><input type='text' maxlength='100' class='textfield' name='pn' size='40' /><br /><br />
MCHN: <br /><input type='text' maxlength='100' class='textfield' name='mchn' size='40' /><br /><br />
DESC: <br /><input type='text' maxlength='100' class='textfield' name='desc' size='40' /><br /><br />
LOC: <br /><input type='text' maxlength='100' class='textfield' name='loc' size='40'  /><br /><br />
PRICE: <br /><input type='text' maxlength='100' class='textfield' name='price' size='40' /><br /><br />
SPARE: <br /><input type='text' maxlength='100' class='textfield' name='spare' size='40' /><br /><br />



<input type='submit' name='submit' value='submit' class='textfield' /></form>";



echo $content;
?>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483820
Share on other sites

RECODED WORKS m8

 

try this.........

<?php session_start();

header("Cache-control: private");

if (isset($_POST['submit'])) {

$pn=mysql_real_escape_string($_POST['pn']);
$mchn=mysql_real_escape_string($_POST['mchn']);
$desc=mysql_real_escape_string($_POST['desc']);
$loc=mysql_real_escape_string($_POST['loc']);
$price=mysql_real_escape_string($_POST['price']);
$spare=mysql_real_escape_string($_POST['spare']);

$sql = "INSERT INTO parts(PN,MCHN,DESC,LOC,PRICE,SPARE) VALUES ('$pn', '$mchn', '$desc',
'$loc', '$price', '$spare')"; 

$result="mysql_query($sql)or die (mysql_error())";

header("Location: newparts.php");

} else {

echo $content;
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>setup account</title>

</head>

<body>


<?php

$content = "<form action='newparts.php' method='POST'>
<br />
PN: <br /><input type='text' maxlength='100' class='textfield' name='pn' size='40' /><br /><br />
MCHN: <br /><input type='text' maxlength='100' class='textfield' name='mchn' size='40' /><br /><br />
DESC: <br /><input type='text' maxlength='100' class='textfield' name='desc' size='40' /><br /><br />
LOC: <br /><input type='text' maxlength='100' class='textfield' name='loc' size='40'  /><br /><br />
PRICE: <br /><input type='text' maxlength='100' class='textfield' name='price' size='40' /><br /><br />
SPARE: <br /><input type='text' maxlength='100' class='textfield' name='spare' size='40' /><br /><br />



<input type='submit' name='submit' value='submit' class='textfield' /></form>";



echo $content;
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483825
Share on other sites

just tested this works fine........

 

<?php 

if (isset($_POST['submit'])) {

$pn=mysql_real_escape_string($_POST['pn']);
$mchn=mysql_real_escape_string($_POST['mchn']);
$desc=mysql_real_escape_string($_POST['desc']);
$loc=mysql_real_escape_string($_POST['loc']);
$price=mysql_real_escape_string($_POST['price']);
$spare=mysql_real_escape_string($_POST['spare']);

$sql = "INSERT INTO parts(PN,MCHN,DESC,LOC,PRICE,SPARE) VALUES ('$pn', '$mchn', '$desc',
'$loc', '$price', '$spare')"; 

$result="mysql_query($sql)or die (mysql_error())";

} else {

header("Location: newparts.php");

}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>setup account</title>

</head>

<body>


<form action='newparts.php' method='POST'>
<br />
PN: <br /><input type='text' maxlength='100' class='textfield' name='pn' size='40' /><br /><br />
MCHN: <br /><input type='text' maxlength='100' class='textfield' name='mchn' size='40' /><br /><br />
DESC: <br /><input type='text' maxlength='100' class='textfield' name='desc' size='40' /><br /><br />
LOC: <br /><input type='text' maxlength='100' class='textfield' name='loc' size='40'  /><br /><br />
PRICE: <br /><input type='text' maxlength='100' class='textfield' name='price' size='40' /><br /><br />
SPARE: <br /><input type='text' maxlength='100' class='textfield' name='spare' size='40' /><br /><br />



<input type='submit' name='submit' value='submit' class='textfield' /></form>



</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483829
Share on other sites

ok programmers what wrong with this code please dosent work according to user!

 

<?php 

if (isset($_POST['submit'])) {

$pn=mysql_real_escape_string($_POST['pn']);
$mchn=mysql_real_escape_string($_POST['mchn']);
$desc=mysql_real_escape_string($_POST['desc']);
$loc=mysql_real_escape_string($_POST['loc']);
$price=mysql_real_escape_string($_POST['price']);
$spare=mysql_real_escape_string($_POST['spare']);

$sql = "INSERT INTO parts(PN,MCHN,DESC,LOC,PRICE,SPARE) VALUES ('$pn', '$mchn', '$desc',
'$loc', '$price', '$spare')"; 

$result="mysql_query($sql)or die (mysql_error())";

} else {

header("Location: newparts.php");

}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>setup account</title>

</head>

<body>


<form action='newparts.php' method='POST'>
<br />
PN: <br /><input type='text' maxlength='100' class='textfield' name='pn' size='40' /><br /><br />
MCHN: <br /><input type='text' maxlength='100' class='textfield' name='mchn' size='40' /><br /><br />
DESC: <br /><input type='text' maxlength='100' class='textfield' name='desc' size='40' /><br /><br />
LOC: <br /><input type='text' maxlength='100' class='textfield' name='loc' size='40'  /><br /><br />
PRICE: <br /><input type='text' maxlength='100' class='textfield' name='price' size='40' /><br /><br />
SPARE: <br /><input type='text' maxlength='100' class='textfield' name='spare' size='40' /><br /><br />



<input type='submit' name='submit' value='submit' class='textfield' /></form>



</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483842
Share on other sites

The word DESC is a reserved word in MySQL. If you want to use it as a column name, you need to enclose it in backticks "[red]`[/red]".

 

<?php
$result = MYSQL_QUERY("INSERT INTO parts (PN,MCHN,`DESC`,LOC,PRICE,SPARE)".
"VALUES ('$pn', '$mchn', '$desc', '$loc', '$price', '$spare')") or die (mysql_error());
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/94477-whats-this-error/#findComment-483843
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.