shane85 Posted April 1, 2010 Share Posted April 1, 2010 sorry for all the posts today guys... I have a page where im editing a row (clients information) from my database I access it by edit_prospect?=prospect_id=5 (or whatever the prospect_id number is set in the database) I then have my text fields extra but I have values in them which would be the values that are pulled from the database, so that if need be it can be edited. I then setup my form to go to edit_prospect2.php, in which I have a query that im trying to update my database, but it keeps telling my query failed. I have tried 2 different querys...1 with SET and it gives me the same results...the ones I have been trying are $qry = "UPDATE prospects SET(representative, prospect_feeling, firstname, lastname) VALUES('$representative','$prospect', '$f_name', '$l_name')"; which doesnt work, as well as $qry = "UPDATE prospects (representative, prospect_feeling, firstname, lastname) VALUES('$representative','$prospect', '$f_name', '$l_name')"; what am I doing wrong ??? Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 1, 2010 Share Posted April 1, 2010 This is the update syntax definition - UPDATE [LOW_PRIORITY] [iGNORE] table_reference SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/#findComment-1035513 Share on other sites More sharing options...
jcbones Posted April 1, 2010 Share Posted April 1, 2010 Using the above syntax def. $qry = "UPDATE prospects SET representative='$representative', prospect_feeling='$prospect', firstname= '$f_name', lastname= '$l_name'"; //You would probably want to add a WHERE clause onto that, or every row in the table will update. Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/#findComment-1035527 Share on other sites More sharing options...
shane85 Posted April 1, 2010 Author Share Posted April 1, 2010 hmm ok. Makes sence I have to include WHERE so that it knows to update the row. So for WHERE im putting prospect_id='$prospect_id' but its still having the same error. $qry = "UPDATE prospects SET(representative, prospect_feeling, firstname, lastname) VALUES('$representative','$prospect', '$f_name', '$l_name') WHERE prospect_id='$prospect_id'"; I even tried using a number instead of $prospect_id that co-insidees with my db for testing purposes, but still returns the query failed. Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/#findComment-1035528 Share on other sites More sharing options...
shane85 Posted April 1, 2010 Author Share Posted April 1, 2010 I think I figured out why it wasnt working...my variable $prospect_id wasnt being told to GET it in my query...now I have it as follows $qry = "UPDATE prospects SET representative='$representative', prospect_feeling='$prospect', firstname= '$f_name', lastname= '$l_name' WHERE prospect_id='.$_GET['prospect_id'].'"; but its giving me an error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING before when I had it for prospect_id='37'"; it would work perfectly and update that row, but I want it to update from the variable $prospect_id that I need to use GET for I think? Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/#findComment-1035554 Share on other sites More sharing options...
jcbones Posted April 1, 2010 Share Posted April 1, 2010 Try: $id = (isset($_GET['prospect_id'])) ? (int)$_GET['prospect_id'] : die('error!'); $qry = "UPDATE prospects SET representative='$representative', prospect_feeling='$prospect', firstname= '$f_name', lastname= '$l_name' WHERE prospect_id='$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/#findComment-1035556 Share on other sites More sharing options...
shane85 Posted April 1, 2010 Author Share Posted April 1, 2010 works, thank you Quote Link to comment https://forums.phpfreaks.com/topic/197290-update-query-for-database/#findComment-1035558 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.