Jahed
Jahed

Reputation: 75

Simple PHP Error

I have a simple php error coming up of which i cannot find the solution to. I inserted in the following code:

    <?php
session_start();
require_once '../includes/db.php';  

$address1 = $_REQUEST["address1"];
$address2 = $_REQUEST["address2"];
$city = $_REQUEST["city"];
$postcode = $_REQUEST["postcode"];

mysql_query("UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."')")

or die(mysql_error());

?> 

This code gives me the following 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 ')' at line 1

Line 1 is the following in which i think it has nothing to do with the sql statement:

    <?php
session_start();
?>

Thanks everyone! :)

Upvotes: 1

Views: 118

Answers (6)

student
student

Reputation: 213

I think you've forgotten to place a semicolon at the end?

the right one below:

mysql_query(" UPDATE customers SET address1='$address1', address2='$address2',city='$city', postcode='$postcode' WHERE username ='". $_SESSION['username']."'");

Upvotes: 0

KodeFor.Me
KodeFor.Me

Reputation: 13511

Change that line:

mysql_query("UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."')")

to that

mysql_query("UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."'")

You have an extra right parenthesis in the query.

Upvotes: 5

Hamikzo
Hamikzo

Reputation: 254

Change

$_SESSION['username']."')")

to

$_SESSION['username']."'")

Upvotes: 2

Marcus
Marcus

Reputation: 12586

You have a ) in the end of the query that's not supposed to be there.

mysql_query("UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."'")

Upvotes: 3

gen_Eric
gen_Eric

Reputation: 227240

mysql_query("UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."')") or die(mysql_error());

You have a stray ) at the end of your SQL query.

It should be:

mysql_query("UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."'") or die(mysql_error());

Upvotes: 2

Naftali
Naftali

Reputation: 146300

  1. That is open to bobby-tables
  2. Make sure that:

    UPDATE customers SET address1='$address1', address2='$address2', city='$city', postcode='$postcode' WHERE username = '".$_SESSION['username']."')
    

    is a real query.
    Which you can now see that it isn't because of the extra ) at the end

Upvotes: 3

Related Questions