I keep 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 '1' at line 1. I honestly don't see where i might have gone wrong

case "Update":
if(isset($firstname, $lastname, $phone, $address, $city, $state, $zip))
{

mysql_select_db("webuser23", $dbc);
$query = ("UPDATE customers SET firstname = '$firstname' OR lastname = '$lastname' OR phone = '$phone' OR address = '$address' OR city = '$city' OR state = '$state' OR zip = '$zip' WHERE customernumber = '$id' ");
$result = mysql_query($query);
    if (!mysql_query($result, $dbc))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record updated";

mysql_close($dbc);
Member Avatar
LastMitch

I keep 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 '1' at line 1

Did you put these tags <?php?>?

By the way what is case: "update" it looks incomplete.

<?php
case "Update":
if(isset($firstname, $lastname, $phone, $address, $city, $state, $zip))
{
mysql_select_db("webuser23", $dbc);
$query = ("UPDATE customers SET firstname = '$firstname' OR lastname = '$lastname' OR phone = '$phone' OR address = '$address' OR city = '$city' OR state = '$state' OR zip = '$zip' WHERE customernumber = '$id' ");
$result = mysql_query($query);
if (!mysql_query($result, $dbc))
{
die('Error: ' . mysql_error());
}
echo "1 record updated";
mysql_close($dbc);
?> 

I have three cases on switch: "Create" and "search" cases already work. Now it is just the "update". It is part of a longer code.

Member Avatar
LastMitch

MySQL server version for the right syntax to use near '1' at line 1

The error said line 1 which is this

case "Update":

Another words you need to show your Switch statement.

Did you add a break;?

That's error can't be line 1 unless you have this in a separate file?

Member Avatar
LastMitch

Actually you forgot a } close bracket.

hai Edwinner,

can you explain what you are going to do with the following query

$query = ("UPDATE customers SET firstname = '$firstname' OR lastname = '$lastname' OR phone = '$phone' OR address = '$address' OR city = '$city' OR state = '$state' OR zip = '$zip' WHERE customernumber = '$id'");

Note: dont need of paranthesis at thw begining '(' and end ')'of the above statement

I already took the parenthesis out earlier. It was part of mysql_query()

Member Avatar
LastMitch

I already took the parenthesis out earlier. It was part of mysql_query()

No, you are missing a close bracket:

You have this

<?php
case "Update":
if(isset($firstname, $lastname, $phone, $address, $city, $state, $zip))
{
if (!mysql_query($result, $dbc))
{
die('Error: ' . mysql_error());
}
echo "1 record updated";
mysql_close($dbc);
?> 

It should look like this:

<?php
case "Update":
if(isset($firstname, $lastname, $phone, $address, $city, $state, $zip))
{
if (!mysql_query($result, $dbc))
{
die('Error: ' . mysql_error());
}
echo "1 record updated";
}
mysql_close($dbc);
?> 

If that's not the issue then it has something to do with your Switch statement.

Post the code Switch statement if the bracket is not the issue.

Actually Lastmitch, it is my address update values. They are strings from a textarea. Without the address field, the update works fine. Now i need to figure out how to assign values to a textarea and update them well wthout errors! Any suggestions-welcome.

Member Avatar
LastMitch

Now i need to figure out how to assign values to a textarea and update them well wthout errors!

I'm confused now.

You mention there's an error on line 1 is that solve yet?

What was the solution?

I mean if there was something wrong with your query it should be an error appearing on line 6 but so far the only error you mention is line 1?

I don't see any HTML <form> code.

I only see just PHP code.

It is fixed. I don't even know what exactly fixed it. But thanks.