0

What is wrong with this query? It appears to be correct to me:

mysql_query("UPDATE culture SET cult_desc=$culture WHERE cult_id is $UID");

Modified it, NetBeans is still giving me an error. Here's my total code for the page:

$culture = $_POST["culture"];
if (isset($_POST["id"]))
    $UID = $_POST["id"];
    mysql_query("UPDATE culture SET cult_desc='$culture' WHERE cult_id=$UID");
else
     mysql_query("INSERT INTO culture
             VALUES(cult_desc='$culture')");
2
  • Why do you think there is something wrong? Commented Nov 21, 2011 at 18:44
  • because there obviously was something wrong Commented Nov 21, 2011 at 19:09

8 Answers 8

2

what's the value of $culture? If it's a string, you'll need to encapsulate it with quotes.

Same thing for $UID.

Also, The 'is' in the where-condition should be '='

Also: watch our with this code. Make sure that $culture and $UID can not contain any malicious values (e.g. malicious input from users)

Sign up to request clarification or add additional context in comments.

1 Comment

This is an internal admin system, so there won't be malicious values.
2

cult_desc probably string so need to wrap with ' '

mysql_query("UPDATE culture SET cult_desc='$culture' WHERE cult_id = $UID");

Comments

1

Seeing the newly edited code, your update-statement is now correct, but your insert statement now is wrong.

Try:

mysql_query("INSERT INTO culture (culture_desc)
             VALUES ('$culture')");

Comments

1

if SET cult_desc is a string then

mysql_query("UPDATE culture SET cult_desc='$culture' WHERE cult_id = $UID");

or

mysql_query("UPDATE culture SET cult_desc=$culture WHERE cult_id = $UID")

Comments

1

your problem in the { and } of if else statement

$culture = $_POST["culture"];
if (isset($_POST["id"])){
    $UID = $_POST["id"];
    mysql_query("UPDATE culture SET cult_desc='$culture' WHERE cult_id=$UID");
}else{
     mysql_query("INSERT INTO culture
             VALUES(cult_desc='$culture')");
}

Comments

0
$sql = "UPDATE 'culture' SET `cult_desc` = '$culture' WHERE `cult_id` = '$UID'";

Basically, you're using is instead of =

Comments

0

Depending on the data type of $culture and $UID you might be missing quotes. Cult_desc sounds like a string and thus $culture should be enclosed in quotes.

Comments

0

You should always check the output of mysql_error.http://php.net/manual/en/function.mysql-error.

I also usually use = instead of 'is' and also wrap all of my input data in quotation marks. eg

$sql = "UPDATE 'culture' SET cult_desc = '".$culture."' WHERE cult_id = '".$UID."'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.