spdwrench Posted October 17, 2007 Share Posted October 17, 2007 I am having some trouble with mysql sytanx I need to update a table.. the table is phpbb3_config it has 3 fields config_name config_value is_dynamic I need to use a sql=" >>>>>" how would I insert a variable called $user into config_value where config_name is newest_user also need to insert newest user ID from a variable $newid need to insert the user id into config_value where config_name is newest_user_id Please help me with the syntax I am new to mysql but understand a bit... the table and fields already exist I just need to write the new values from the variables. can I do this with one querry? thanks for any help on this in advance.. Paul Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 18, 2007 Share Posted October 18, 2007 Yes you can INSERT INTO phpbb3_config ( 'User_Id', `config_name` , `config_value` , `is_dynamic` ) VALUES ( '$newid','' , '$user', '' ) WHERE config_name='newest_user' AND config_id='new_userid'; This is the way to insert but your values are confusing, same value in 2 fields ??? please check Quote Link to comment Share on other sites More sharing options...
fenway Posted October 18, 2007 Share Posted October 18, 2007 There is no INSERT INTO where with values!!! You need to use INSERT INTO.. .SELECT ... WHERE and write a proper query... but it sounds like the poster wanted an update anyway. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 18, 2007 Share Posted October 18, 2007 There is no INSERT INTO where with values!!! You need to use INSERT INTO.. .SELECT ... WHERE and write a proper query... what does this mean fenway... 'm confused ??? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 19, 2007 Share Posted October 19, 2007 It means that you can't have a WHERE clause in an INSERT statement. Look here. Quote Link to comment Share on other sites More sharing options...
spdwrench Posted October 21, 2007 Author Share Posted October 21, 2007 thanks for the help guys I got it working and your right the 2 values should not be the same but I cheated a little because it is only a totaly member count and does not need to be exact.. Paul this is what I ended up doing $sql="UPDATE phpbb3_config SET config_value ='$login' WHERE config_name ='newest_username' "; q($sql); $sql="UPDATE phpbb3_config SET config_value ='$phpbb_userid' WHERE config_name ='num_users' "; q($sql); $sql="UPDATE phpbb3_config SET config_value ='$phpbb_userid' WHERE config_name ='newest_user_id' "; q($sql); if you have some better code to put it all into one query please post... I am a little unpolished but I got it to work Paul 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.