Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in updating data

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello i m having difficulty in updating a form, i created a form which has two buttons, one is for edit and one is for update, but when i am updating my data after editing, it update 0 instead of the data, i mean i m getting 0 in my db, data is replaced to 0, here is my code:

 
Nick Charles
Ranch Hand
Posts: 71
Linux PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, never ever write code like this. Never build an SQL query by concatenating user input, such code is subject to an SQL injection attack. You would be better off using mysqli::query() and then passing the parameters using mysqli_stmt::bind_param().

Second, your UPDATE statement lacks a WHERE clause. Therefore, ALL records in the database will be updated with this information.

Finally, I tried your code (though I reduced the database to three columns), and it updated just fine for me (though, of course, all rows in the database now have the same values). I assume that the file was named update.php.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay it's working for me...
but how mysql_query can cause sql injuctions??
i use mysql_query in each of my database query...
 
Nick Charles
Ranch Hand
Posts: 71
Linux PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How? By someone entering something like "foo; delete * from stu_form;..." in the name field of yous form. You should read up on sql injection. And never ever code like this again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i will use mysql_real_escape_string to prevent from sql injuctions..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic