Jump to content

Having an issue with UPDATING SQL Database via PHP Table


mbb87

Recommended Posts

As one other contributor noted the table name should be in backticks (or none at all). However, the query is fine. The query I provided doesn't need a WHERE clause and using one would actually make it fail to produce the correct results. I actually tested this logic on a table so I know it works. Let me explain how it works because it is not completely obvious how it works but is actually pretty ingenious in my humble opinion.

 

I have to agree, that is an elegant solution. Sorry, I did not get it at first. It is just the kind of solution I look for to avoid IF's and CASE's and looping queries.

 

@mbb87 The reason it is updating rows you don't want it to is because you are not limiting the update to the specific team you are dealing with. Since we haven't actually seen the query that selects the list of players, we can't offer a complete solution. However, some kind of WHERE clause selecting the team in question should work. If the database is normalized, it would require a JOIN to the table that links players to their team. You would have to pass the team ID in a session field (preferred) or a hidden form field (not recommended) between the two scripts.

 

Sorry, I missed the quotes (instead of backticks) on the table name and sent you down the wrong road. For the record, I never use backticks on table or column names. If I accidentally use a reserved word for a (table or column) name, I change the name. While using backticks is permitted (not required); it makes the code more difficult to read (IMO) and leads to problems if you forget them or inadvertently use single-quotes. I just eliminate the potential problems by not using reserved words for names and therefore not needing to use backticks.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.