Jump to content

MySQL UPDATE not working


jonoc33

Recommended Posts

Hi there,

 

Ok, so this is a profile edit script. Basically what it does is checks if you've entered something in the textboxes on the previous page if you have put anything in the password boxes and then changes the data according to what you put in. Otherwise, if you haven't put anything in the password boxes and don't want to change your password it just changes all the fields except the passwords. It then registers Sessions according to what you entered. Read below and see if you find any errors.

 

<?php
session_start();
include("include/db.php");
$cpass = mysql_real_escape_string($_POST['cpass']);
$npass = mysql_real_escape_string($_POST['npass']);
$rnpass = mysql_real_escape_string($_POST['rnpass']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$showemail = $_POST['showemail'];
$location = mysql_real_escape_string($_POST['location']);
$age = mysql_real_escape_string($_POST['age']);
$fg = mysql_real_escape_string($_POST['fg']);
$fq = mysql_real_escape_string($_POST['fq']);
$website = mysql_real_escape_string($_POST['website']);
$gender = mysql_real_escape_string($_POST['gender']);
$yim = mysql_real_escape_string($_POST['yim']);
$aim = mysql_real_escape_string($_POST['aim']);
$msn = mysql_real_escape_string($_POST['msn']);
$icq = mysql_real_escape_string($_POST['icq']);
$sig = mysql_real_escape_string($_POST['sig']);
$encryptpass = md5($npass);
if($showemail == "1"){
$showemail2 = "1";
}
else{
$showemail2 = "0";
}

if(strlen($cpass) >> 0){
if($npass == $rnpass){
	if(md5($cpass) == $_SESSION['encryptpass']){
		if(mysql_query("UPDATE users SET encryptpass = '".$encryptpass."', password = '".$npass."', email = '".$email."', showemail = '".$showemail2."', name = '".$name."', location = '".$location."', age = '".$age."', favouritegames = '".$fg."', favouritequote = '".$fq."', website = '".$website."', gender = '".$gender."', aim = '".$aim."', yim = '".$yim."', icq = '".$icq."', msn = '".$msn."' WHERE username='".$_SESSION['username']."'")){

			$_SESSION['encryptpass'] = $encryptpass;
			$_SESSION['email'] = $email;
			$_SESSION['name'] = $name;
			$_SESSION['location'] = $location;
			$_SESSION['age'] = $age;
			$_SESSION['fg'] = $fg;
			$_SESSION['website'] = $website;
			$_SESSION['gender'] = $gender;
			$_SESSION['icq'] = $icq;
			$_SESSION['aim'] = $aim;
			$_SESSION['yim'] = $yim;
			$_SESSION['msn'] = $msn;
			$_SESSION['fq'] = $fq;
			$_SESSION['showemail'] = $showemail2;

			echo "<center>Profile updated.<br /><br /><a style='color: #000000;' href='index.php?page=members'>Back</a></center>";
		}
		else{
			echo mysql_error();
		}
	}
	else{
		echo "The password you inputted does not match your current password. Please try again.<br /><a href='index.php?page=members'>Back</a>";
	}
}
else{
	echo "The two passwords do not match. Please try again.<br /><a href='index.php?page=members'>Back</a>";
}	
}
else{
if(mysql_query("UPDATE users SET email = '".$email."', showemail = '".$showemail2."', name = '".$name."', location = '".$location."', age = '".$age."', favouritegames = '".$fg."', favouritequote = '".$fq."', website = '".$website."', gender = '".$gender."', aim = '".$aim."', yim = '".$yim."', icq = '".$icq."', msn = '".$msn."' WHERE username='".$_SESSION['username']."'")){

	$_SESSION['email'] = $email;
	$_SESSION['name'] = $name;
	$_SESSION['location'] = $location;
	$_SESSION['age'] = $age;
	$_SESSION['fg'] = $fg;
	$_SESSION['fq'] = $fq;
	$_SESSION['website'] = $website;
	$_SESSION['gender'] = $gender;
	$_SESSION['icq'] = $icq;
	$_SESSION['aim'] = $aim;
	$_SESSION['yim'] = $yim;
	$_SESSION['msn'] = $msn;
	$_SESSION['sig'] = $sig;
	$_SESSION['showemail'] = $showemail2;

	echo "<center>Profile updated.<br /><br /><a href='index.php?page=members'><img border='0' src='images/button_back.jpg'></a></center>";
}
else{
echo mysql_error();
}
}
?>

 

See any errors? I didn't.

 

Now get this. When I input the fields I want to change and hit edit, it updates the database and makes all those fields in the UPDATE query set to nothing.

It's like all the variables don't have any values in them. Yes, I checked, and they do. The field names are all correct, all the variable names in the query are correct, all the post data names are correct, but strangely enough it just makes all those columns blank.

 

Basically, the columns that turn blank after the UPDATE query are these ones:

email = '".$email."', showemail = '".$showemail2."', name = '".$name."', location = '".$location."', age = '".$age."', favouritegames = '".$fg."', favouritequote = '".$fq."', website = '".$website."', gender = '".$gender."', aim = '".$aim."', yim = '".$yim."', icq = '".$icq."', msn = '".$msn."' WHERE username='".$_SESSION['username']."'

All of the variables have values.

If you want to change your password, it changes fine, but nothing else does.

It is quite weird because it USED to work, but now it doesn't.

 

Help?  ???

Link to comment
https://forums.phpfreaks.com/topic/97931-mysql-update-not-working/
Share on other sites

Hiya,

 

Before I start let me just say I am no genius but I get by (Just)

 

I have a similar query on one of my sites but I have written the update query string slightly different

 

mysql_query("update table set email='$email' where id='$row[id]'");

 

Hope that helps.

 

Lyle

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.