• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Any PHP mysqli experts?

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Any PHP mysqli experts?

    Doing a website for local history society and need a page for them to update the agenda list. Even a very simplified line doesn't work:

    $sql = $con->query("UPDATE whlist SET date='$date' WHERE id='$id'");
    if ($con->query($sql) <> TRUE) {echo $con->error;}

    Getting:

    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

    Echo shows all valid values. Tried variations, id=1, enclosing in quotes as per some online stuff. I've used much more complicated update lines in other code with no problem and can't see what's wrong here. Any ideas? Cheers.
    Last edited by xoggoth; 24 July 2023, 10:37.
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    #2
    MySQL is not really my thing but is the 'whilst' needed? sounds like a loop command rather than a straight forward UPDATE (1), VALUES (blah)...
    Unless I'm missing your loop code somewhere in your PHP?

    Ah my mistake whilst is your table name?

    Then I got nothing...

    Comment


      #3
      Yeh, stands for <village name> list. West summit or other, not giving me location away, Putin will find out.
      bloggoth

      If everything isn't black and white, I say, 'Why the hell not?'
      John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

      Comment


        #4
        I'd try this and see if it still throws a syntax error.

        UPDATE whlist SET foobar=1 WHERE id=1

        Comment


          #5
          I don't think you are concatenating your strings and variables correctly. Try


          $sql = $con->query("UPDATE whlist SET date='" . $date . "' WHERE id='" . $id . "'");

          Comment


            #6
            Cheers. That does update row 1 but still get error messages.
            bloggoth

            If everything isn't black and white, I say, 'Why the hell not?'
            John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

            Comment


              #7
              What errors do you get ?

              Comment


                #8
                Ah! I didn't see the relevance of your comment initially but you've sorted it for me, I just updated each item individually and it worked.

                $sql = $con->query("UPDATE whlist SET date='$date' WHERE id=$id");
                $sql = $con->query("UPDATE whlist SET title='$title' WHERE id=$id");
                $sql = $con->query("UPDATE whlist SET speaker='$speaker' WHERE id=$id");
                $sql = $con->query("UPDATE whlist SET description='$description' WHERE id=$id");

                $con->error still showing same error message but I'll just comment that out.

                Thanks woody1

                Can't understand why I never had this problem before in my business website, got lots of far more complicated update lines. Maybe some property of the table?
                Last edited by xoggoth; 24 July 2023, 13:06.
                bloggoth

                If everything isn't black and white, I say, 'Why the hell not?'
                John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

                Comment


                  #9
                  Originally posted by xoggoth View Post
                  Cheers. That does update row 1 but still get error messages.
                  Presumably you changed foobar for an actual column? Strange that it now updates a row but still throws errors, although presumably not a syntax error.

                  As a pure guess, the syntax error might have been something to do with the $var and/or single quotes.

                  Comment


                    #10
                    Originally posted by xoggoth View Post
                    Thanks woody1
                    No problem, although I was just groping in the dark.

                    Anyway, ignore my previous post.

                    Comment

                    Working...
                    X