Jump to content

[SOLVED] UPDATE issues


spa1969

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.