Hey..
Need help tweaking a bit of code in a module I'm playing with.
What I need to do is
a) check to see if a field exists in a table
b) if one exists...update it with a new setting
c) if the field doesn't exist, insert a new one.
am googled to death searching through help sites for php & mysql and thought I would post up here in case someone would spot it quickly.
the table striucture is as follows and is designed to store a link as the "home page" link of the site...i.e. the next time they log in they are redirected to that page.
table name = frontlink
column 1 = uid
column 2= front_url
So the table stores a "front url" for each user and is keyed by the user ID.
below is the function to write the information to the database and table. I'm a novice at this so I pasted an existing "save" function from another module and edited it. (apologies in advance)
function quicklinks_front_save($edit) {
global $user;
$edit['old_front_url'] = urldecode($edit['old_front_url']);
if ($edit['old_front_url'] && db_result(db_query("SELECT COUNT(uid) FROM {frontlink} WHERE uid = %d AND front_url = '%s'", $user->uid, $edit['old_front_url']))) {
db_query("UPDATE {frontlink} SET front_url = '%s' WHERE uid = $user->uid AND front_url = '%s'");
drupal_set_message(t('Your front page has been updated.'));
}
else {