Jump to content

Using PHP with MySQL - code doesn't work, but is parsed OK


Freedom-n-Democrazy

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ::)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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! ;D

Link to comment
Share on other sites

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.

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.