Jump to content

Two fields won't write back to database :(


NathanS

Recommended Posts

Hi guys,

 

Got a highly random problem which I can't figure out - have an "edit profile page" where you can fill in info about yourself, and it writes back to a MySQL database.

 

All fields work fine apart from two: Gender and Website.

 

The code is below - anyone any ideas what on earth I'm doing wrong?

 

Thanks!

 

if ($_POST["submit"]) {
$form["fullname"] = htmlspecialchars(trim($_POST["fullname"]));
$form["location"] = htmlspecialchars(trim($_POST["location"]));
$form["website"] = htmlspecialchars(trim($_POST["website"]));;
$form["gender"] = htmlspecialchars(trim($_POST["gender"]));;
$form["favbands"] = htmlspecialchars(strip_tags(trim($_POST["favbands"])));
$form["bio"] = htmlspecialchars(strip_tags(trim($_POST["bio"])));
$form["level"] = (int)$_POST["level"];

if ($form["gender"] && $form["gender"] != "M" && $form["gender"] != "F") {
	$form["gender"] = "";
}

if ($_FILES["avatar"]["name"]) {
	$size = getimagesize($_FILES["avatar"]["tmp_name"]);
	if ($size[0] <= 100 && $size[1] <= 100 && $_FILES["avatar"]["size"] <= 112640) {
		$current_av = $user->get_avatar();
		if (file_exists($current_av) && $current_av != "images/default_av.png") {
			unlink($current_av);
		}
		$new_av = "images/avatars/".$user->_id.".".substr(strrchr($_FILES["avatar"]["name"], '.'), 1);
		move_uploaded_file($_FILES["avatar"]["tmp_name"], $new_av);
	}
}

$user->_fullname = $form["fullname"];
$user->_location = $form["location"];
if (ereg("^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\._\?\,\'/\\\+&%\$#\=~\-])*$", 

$form["website"]) || (!$form["website"])) {
	$user->_website = $form["website"];
}
$user->_gender = $form["gender"];
$user->_favbands = $form["favbands"];
$user->_bio = $form["bio"];
if ($me->_level >= 3) {
	$user->_level = $form["level"];
}
$user->update_profile();
$saved = true;

 

And the writing back to database:

 

	function update_profile() {
	@mysql_query("update `members` set `fullname` = '".sanitize_sql_string($this->_fullname)."', `location` = '".sanitize_sql_string($this->_location)."', `birthday` = '".sanitize_sql_string($this->_birthday)."', `website` = '".sanitize_sql_string($this->_website)."', `gender` = '".sanitize_sql_string($this->_gender)."', `favbands` = '".sanitize_sql_string($this->_favbands)."', `bio` = '".sanitize_sql_string($this->_bio)."', `level` = ".$this->_level." where `id` = ".$this->_id." limit 1");
}

Link to comment
https://forums.phpfreaks.com/topic/116952-two-fields-wont-write-back-to-database/
Share on other sites

have you tried using print_r() on the posted data, to see if a value is set for it? did you try to echo both variables, and see that they contain a value before being written to database (echo at the latest possible moment, just before everything is written to the database)?

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.