469,281 Members | 2,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

drop down menu list update *help*

201 100+
i can query the list fine using:

Expand|Select|Wrap|Line Numbers
  1. select list.list, many_table.list_id_fk from list left join many_table
  2. on list.id = many_table.list_id_fk and many_table.userid = 'UserId';
  3.  
that populates the list per user id.

now when the user selects a new item from the list
it does not update

here is the update query:
Expand|Select|Wrap|Line Numbers
  1. $updateSQL = sprintf("UPDATE list_many SET list_many_id_fk=%s, UserIdFk='1', `Date`=now() WHERE Id=%s",
  2. GetSQLValueString($_POST['list_many_idfk'], "int"),
  3. GetSQLValueString($_POST['UserIdFk'], "int"),
  4. GetSQLValueString($_POST['Date'], "date"),
  5. GetSQLValueString($_POST['Id'], "int"))
  6.  
thanks in advance for your help!

theo
Sep 23 '09 #1
7 2502
TheServant
1,168 Expert 1GB
Can I just ask why you are using that method to update your tables? Why haven't you used something like:
Expand|Select|Wrap|Line Numbers
  1. $list_many_idfk = $_POST['list_many_idfk'];
  2. $userIdFk  $_POST['UserIdFk'];
  3. $date  $_POST['Date'];
  4. $id = $_POST['id'];
  5.  
  6. $result = mysql_query("UPDATE list_many SET list_many_id_fk=$list_many_id_fk, UserIdFk='1', `Date`=now() WHERE Id=$id");
I think that's much easier to read/debug etc... As I say, I don't know much about this method, but are you sure you can set default values for UserIDFk and Date?
Sep 23 '09 #2
Dormilich
8,651 Expert Mod 8TB
in sprintf() there are only the indicated values (%s, …) replaced, you have 2x %s but 4 values, obviously, the last two are therefore not used.
Sep 23 '09 #3
wizardry
201 100+
no problem neither did i, until i started programming it and using it. that method ( GetSQLValueString) calls a function which checks for sql injection, etc... you can log it if it fails, suspects, etc...

I prefer this method. less issues in the long run.

yes you can changed the %s to include a default record to set that should be in the where i switched them around. not worried about id. just the users record that is being updated.

************************************************** *********

ok -

this is what i'm trying to do.

pull data from a list table, for the fk in the many table and allow the user to update by using the drop down menu.

i have the drop down menu pulling the records and defaults on the record stored in the many table. its just the update is failing.

any help is appreciated.

ive tried doing a join update which works in mysql but php doesnt like it.
Sep 23 '09 #4
Dormilich
8,651 Expert Mod 8TB
@wizardry
this should be no concern of PHP since it is only a string. if PHP doesn’t like it, there should be at least an notice/warning/error message.
Sep 23 '09 #5
TheServant
1,168 Expert 1GB
@wizardry
Interesting, thanks. Well because I don't know the function myself, and for the next 8 hrs I will not be able to test it out, I recommend you do this:
Make a simple MySQL query (using GetSQLValueString) and bit by bit add small components to change it in your code until it doesn't work - that will be your problem, or atleast one fo them. It's the long way round, but I think you will get a result quicker.

Failing that, wait until another expert comes along to this post and spots it without reading twice :P
Sep 23 '09 #6
wizardry
201 100+
this has been resolved!

i needed to limit what the form was updating, just the list fk id and date that the new update was entered.

Expand|Select|Wrap|Line Numbers
  1. $updateSQL = sprintf("update ASBodyType as a
  2.               left join BSType as b
  3.         on b.Id = a.BodyType
  4.         set a.BodyType=%s, a.Date=now()
  5.              where a.UIdFk='1'",
  6.            GetSQLValueString($_POST['BodyType'], "int"));

thanks again for your help!
Sep 24 '09 #7
TheServant
1,168 Expert 1GB
Your code looks a little different with the BodyType, so still unclear what the problem was, but glad you got it solved.
Sep 24 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by hemanth.singamsetty | last post: by
1 post views Thread by StevePBurgess | last post: by
4 posts views Thread by Laura K | last post: by
4 posts views Thread by TycoonUK | last post: by
7 posts views Thread by wizardry | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.