• 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?

xoggoth

More fingers than teeth
Joined
Jul 8, 2005
Messages
17,131
Likes received
4,950
Thanks received
1,184
Location
xoggoth towers
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: 11:27
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...
 
Yeh, stands for <village name> list. West summit or other, not giving me location away, Putin will find out.
 
I'd try this and see if it still throws a syntax error.

UPDATE whlist SET foobar=1 WHERE id=1
 
I don't think you are concatenating your strings and variables correctly. Try


$sql = $con->query("UPDATE whlist SET date='" . $date . "' WHERE id='" . $id . "'");
 
Cheers. That does update row 1 but still get error messages.
 
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: 14:00
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.
 

Advertisers

Back
Top