Hello,
I have this weird problem, I know how to select and insert, BUT I don't know how to UPDATE, well at least I thought I did. And all of the code from tutorials brings back errors. Here's the error I'm getting:
Hello,
I have this weird problem, I know how to select and insert, BUT I don't know how to UPDATE, well at least I thought I did. And all of the code from tutorials brings back errors. Here's the error I'm getting:
Two problems:
1 - You are escaping the single quotes where you should not (and your double quotes are out of order).
2 - The query may be prone to SQL injection.
Try:
$tsql = mysql_query("UPDATE advertisements SET Clicks=Clicks+1, ClicksToday=ClicksToday+1 WHERE AccountNumber='".$aN."'") or die(error());
$tsql = mysql_query("UPDATE advertisements SET Clicks=Clicks+1, ClicksToday=ClicksToday+1 WHERE AccountNumber='".$aN."')" or die(error());
Your mysql_error ENCAPSED_STRING
means that your single and double quotes are wrong. Once you've solved the problem of your quotes as RedFilter mentions, then consider your data.
Some of the problems I have encountered and eventually solved in regards to UPDATE not updating (often times I never saw any errors):
I don't know if any of these suggestions will work for you, but I used to have equal frustration when I couldn't figure out what what (not) going on. These are some of the solutions that worked so that I could eventually UPDATE my tables.
The SELECT
query you are running is collecting four columns, none of which are the account number.
$tsql = "SELECT WebsiteName, WebsiteDescription, WebsiteHeadline, DestinationURL FROM advertisements LIMIT 0,5";
What happens if you change it to add the AccountNumber
field?
$tsql = "SELECT AccountNumber, WebsiteName, WebsiteDescription, WebsiteHeadline, DestinationURL FROM advertisements LIMIT 0,5";
At the moment, because you are not fetching the AccountNumber
field, when you assign your variables, you don't have a $row['AccountNumber']
.
$aN = $row["AccountNumber"];
$du = $row["DestinationURL"];
$wn = $row["WebsiteName"];
$am = $row["WebsiteDescription"];
$ad = $row["WebsiteHeadline"];
I think this is why your UPDATE
query is not updating correctly.