spa1969 Posted September 5, 2007 Share Posted September 5, 2007 Hi all, I'm hoping someone can point me in the right direction with this issue. I have the code below which INSERTS a simple record in my DB (which works fine). The problem I have is that I want to be able to update a record if a specific email address already exists. So far everything I've tried doesn't work even though it all looks correct as far as I can tell. If anyone can point out the mistake or point me in the right direction that would be great. Thanks in advance. S $email = $HTTP_POST_VARS['email_address_sender']; $firstname = $HTTP_POST_VARS['firstname']; $surname = $HTTP_POST_VARS['surname']; $company = $HTTP_POST_VARS['companyname']; $position = $HTTP_POST_VARS['job']; $address = $HTTP_POST_VARS['firstline']; $street = ''; $city = $HTTP_POST_VARS['town']; $postcode = $HTTP_POST_VARS['postcode']; $country = ''; $telephone = $HTTP_POST_VARS['telephone']; $mobile= $HTTP_POST_VARS['mobile']; $fax = $HTTP_POST_VARS['fax']; $bustype = ''; $delegate = ''; $usertype = 'D'; $reg_date = $_POST['reg_date']; $password = makeRandomPassword(); $db = mysql_connect("host", "user","pw"); mysql_select_db("db",$db); $query = "SELECT count(*) FROM subscriptions WHERE email='$email'"; $result = mysql_query($query,$db); $SubscriberExists==false; if ($result){ if (mysql_result($result, 0, 0)>0){ $SubscriberExists==true; } }else{ $registration_message="Unfortunately, there was a problem processing your registration."; $registration_message.="<br>ERROR(1):".$query; } if ($SubscriberExists==true){ $query = "UPDATE subscriptions SET usertype='$usertype', reg_date='$reg_date' WHERE email='$email'"; }else{ $query = "INSERT INTO subscriptions (email,password,firstname,surname,company,position,address,street,city,postcode,country,telephone,mobile,fax,bustype,usertype,reg_date) VALUES ('$email','$password','$firstname','$surname','$company','$position','$address','$street','$city','$postcode','$country','$telephone','$mobile','$fax','$bustype','$usertype','$reg_date')"; $result = mysql_query($query,$db); if ($result && sendUserEmail($email,$password) && sendAdminEmail($email,$password,$firstname,$surname,$company,$position,$address,$street,$city,$postcode,$country,$telephone,$mobile,$fax,$bustype)){ $registration_message="Thank you for your registration, a password will be sent to you by email shortly."; }else{ $registration_message="Unfortunately, there was a problem processing your registration."; $registration_message.="<br>ERROR(2):".$query; } } } Link to comment https://forums.phpfreaks.com/topic/68053-solved-update-issues/ Share on other sites More sharing options...
pocobueno1388 Posted September 5, 2007 Share Posted September 5, 2007 Change this line: if (mysql_result($result, 0, 0)>0){ To: if (mysql_num_rows($result) > 0){ Link to comment https://forums.phpfreaks.com/topic/68053-solved-update-issues/#findComment-342082 Share on other sites More sharing options...
spa1969 Posted September 5, 2007 Author Share Posted September 5, 2007 Thanks pocobueno1388, That did it... S Link to comment https://forums.phpfreaks.com/topic/68053-solved-update-issues/#findComment-342098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.