0

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);
3
Contributors
10
Replies
36
Views
4 Years
Discussion Span
Last Post by Edwinner
0

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);
?> 
0

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.

0

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?

Edited by LastMitch: grammer

0

Actually you forgot a } close bracket.

Edited by LastMitch: grammer

0

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

0

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

0

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.

0

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.

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.