0

Cannot update my table with the follow code...have been trying for hours... tagboard is the table name, mytag1 is what I want to update with reference to emailadd.

$myemail = mysql_real_escape_string( $_POST["myemail"] );
$mytag1 = mysql_real_escape_string( $_POST["mytag1"] );
echo $mytag1;
$query = "UPDATE tagboard SET mytag1='{$mytag1}' WHERE emailadd = {$myemail}";
$result=mysql_query($query);

OR

$sql="UPDATE tagboard SET mytag1 ='".$_POST['mytag1']."' WHERE  myemail='".$_POST['myemail']."'";
$result=mysql_query($sql);

Appreciate your help!

5
  • mysql_error() is your friend Commented Oct 10, 2013 at 19:26
  • Yes can you please post the errors you are getting? Commented Oct 10, 2013 at 19:28
  • @mikeB thanks! --- This is my 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 '@gmail.com' at line 1" What am I suppose to do?? I will google it but if you already know..... Commented Oct 10, 2013 at 19:28
  • You're not quoting your variables. Commented Oct 10, 2013 at 19:32
  • And I caught a few more errors... I called the column tag1 not mytag1 in the table, but I am sending mytag1....Just started learning php recently. Sorry for being stupid. And many thanks! Commented Oct 10, 2013 at 19:36

2 Answers 2

1

Add quotes around your email address field in the query:

$query = "UPDATE tagboard SET mytag1='{$mytag1}' WHERE emailadd = '{$myemail}'";
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much :)) It works for me! Have been figuring this out for a while now
0

You have this line:

$query = "UPDATE tagboard SET mytag1='{$mytag1}' WHERE emailadd = {$myemail}";

Try putting single quotations around the email variable too

$query = "UPDATE tagboard SET mytag1='{$mytag1}' WHERE emailadd = '{$myemail}'";

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.