Freedom-n-Democrazy Posted September 21, 2011 Share Posted September 21, 2011 I am using this PHP code with a MySQL query. PHP parses the PHP fine, but the MySQL query is not having any effect on the database. Can anyone see an error in my code? I can't. $query = "UPDATE `products` set `id` = '".$_POST['id']."' where `id` = '".$_POST['id']."'"; MOD EDIT: Changed PHP manual link tags to . . . tags. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 Echo the query string, and the problem should be readily apparent. Quote Link to comment Share on other sites More sharing options...
jcbones Posted September 21, 2011 Share Posted September 21, 2011 So you are trying to set the id to a row that already has that id? I wonder why it doesn't work. Tell us what you are trying to accomplish, please. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Echo the query string, and the problem should be readily apparent. What does this mean? Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Tell us what you are trying to accomplish, please. Update a MySQL database through a HTML form. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 Echo the query string, and the problem should be readily apparent. What does this mean? Which part did you not understand? Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 You say "echoing the string". What does this mean? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 Uh . . . echo $query; Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Sorry, I am not a womanless computer scientist that has spent half his life on SourceForge. If your going to explain things to me, try it in a spoken language, rather syntaxes. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 I echoed the string. All it did was print my string. That didn't do anything to the database. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Are my syntaxes valid? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 Sorry, I am not a womanless computer scientist that has spent half his life on SourceForge. If your going to explain things to me, try it in a spoken language, rather syntaxes. This is a site for people to get help with php, not to learn it from scratch, or to have it written for them. If you can't understand something as absolutely basic as "echo the query string", you're not going to make it very far. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 I understand what "echoing the string" meant, but echoing the string has nothing to do with what I asked, so I wasn't sure what you meant. I also haven't asked anyone to write me code from scratch, if you bothered to read my original post correctly, you would have seen I have brought my own code and asked if anyone can see a problem with it. This is the whole point of "PHP Coding Help" is it not?! Pikachu2000 your contribution to this thread is nothing but trash and arrogance. Please get out. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 If you'd take the time to read the string that was echoed, instead of acting like a whiny little asshat that wants everything handed to them, you might actually spot the problem. I'm not going to hold your hand and point it out to you. Your query is doing exactly what you've written it to do. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 You mad bro? I'm not going to hold your hand and point it out to you. Thank you for validating my statement about your arrogance and trash. My post asked if anyone can see a problem with my code. If your not going to help me out by pointing out a problem that I cannot see, then why have you bothered to reply to my thread. ... and your an Administrator too, thats unbelievable! If you'd take the time to read the string that was echoed What difference is it going to make seeing the code echoed or in my text editor? Its still the same code that I wrote and can see in my text editor Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2011 Share Posted September 21, 2011 The point is when you echo the code, it is not the same code, if it was, I would not have suggested that you echo the query string. If you'd actually take the time to read what was echoed, you'd see for yourself that you're trying to set the value of the field to the same value it was before the query. Quote Link to comment Share on other sites More sharing options...
gizmola Posted September 21, 2011 Share Posted September 21, 2011 As you say, it is your code, do you understand it? The reason he told you to echo out the sql statement is because you are building it with code. What is important is the final result. I will save you further consternation, by asking this question: UPDATE mytable SET name = 'Freedom' WHERE name = 'Freedom' Now this is equivalent to what your query is doing. Do you see the problem now? Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Do you see the problem now? No. Tell me? So just a bit of a refreshment folks: I am using a HTML forum with PHP to update a MySQL database. I have tried this PHP code: $query = "UPDATE `products` set `category` = '".$_POST['category']."' where `id` = '".$_POST['id']."'"; PHP parses the code, but it has no effect on my database which leads me to suspect a MySQL syntax problem, OR, I've implemented PHP wrong inside my MySQL query. Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 If you'd actually take the time to read what was echoed, you'd see for yourself that you're trying to set the value of the field to the same value it was before the query. No. Its not because of that reason. It is another reason. I will explain why. EDITING... Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Actually, I have a better idea: Forget about the code I have used, this is the new code - same problem applies: $query = "UPDATE `products` set `category` = '".$_POST['category']."' where `id` = '".$_POST['id']."'"; Here is the MySQL database: http://i55.tinypic.com/8yur94.png Now as I said, PHP parses fine, but the MySQL data is not changing when I enter new data in the HTML field. Quote Link to comment Share on other sites More sharing options...
Amit20 Posted September 21, 2011 Share Posted September 21, 2011 $query = "UPDATE `products` set `category` = '".$_POST['category']."' where `id` = '".$_POST['id']."'"; Hey did u tried removing quotes around your table and column names. Something like this. $query = "UPDATE products set category = '".$_POST['category']."' where `id` = '".$_POST['id']."'"; Try it out! Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 Hey Amit, Tried it, but didn't work! I really was excited too lol Thanks anyway bro! Quote Link to comment Share on other sites More sharing options...
patchido Posted September 21, 2011 Share Posted September 21, 2011 first of all..... pikachu was doing things right, you don't really deserve to be helped, the problem is not in your code i guess the post variables you are reading are not set to what you intend them to, try echoing them Quote Link to comment Share on other sites More sharing options...
patchido Posted September 21, 2011 Share Posted September 21, 2011 also... why do you have an id column if it is not unique and AI? Quote Link to comment Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 21, 2011 Author Share Posted September 21, 2011 first of all..... HEY! You should STFU and mind your own business. This is between him and I. ... and that goes for anyone else whom has nothing else better to do with their time. also... why do you have an id column if it is not unique and AI? It will be unique. At the moment the table is a testing ground. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.