notepad Posted April 18, 2007 Share Posted April 18, 2007 Hi, I am in the process of making of login script for my site. So far, I have made a profile page, register page, and login page using PEAR. I am now working on the 'edit_account' page. But I can't seem to get the code right for the update of user data. I need to be able to update several rows, using user posted data. I read the manual reference to update here: http://pear.php.net/manual/en/package.database.db-dataobject.db-dataobject.update.php But I didn't really understand the example, and the example is connecting to the database differently. I have one main 'db_connect' file, and run queries via requiring that file, using the $db variable(which is my database connection). And I don't use the 'new' feature. I have the 'basic' query: $q =& $db->query("UPDATE users SET ".ROW NAME HERE." = '".POST VALUE."' WHERE username = '".$_SESSION['username']."'"); But I can't figure out where to go from here. Can someone point me in the right direction? Sorry if this is a dumb question, I am still quite new to MySQL & PEAR, I have only been using it for a couple of days. Quote Link to comment https://forums.phpfreaks.com/topic/47653-update-multiple-rows-in-user-table/ Share on other sites More sharing options...
btherl Posted April 19, 2007 Share Posted April 19, 2007 The function call for your update query should look the same as your other queries. The best way (in my experience) to do it is like this: $update_sql = "UPDATE users SET ".ROW NAME HERE." = '".POST VALUE."' WHERE username = '".$_SESSION['username']."'"; print "About to run $update_sql<br>"; $q = &$db->query($update_sql); The key here is that you get to see your query before it's sent off to the database. That is very valuable for debugging. The way you call an update is query is identical to how you call other queries. Eg, if you use mysql_query() for your other queries, you should continue using that, instead of $db->query(). Then you should use the "affected rows" function for the interface you're using (either $db->query() or mysql_query()) to see if the update affected any rows. Quote Link to comment https://forums.phpfreaks.com/topic/47653-update-multiple-rows-in-user-table/#findComment-232864 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.