开发者

Database image then update = error, update then image = success! why?

开发者 https://www.devze.com 2023-01-24 03:22 出处:网络
So i am running into a perplexing (programmer caused) bug, me being the programmer. I have created开发者_如何学运维 a website with user profile.The user profile has many fields and an image.The image

So i am running into a perplexing (programmer caused) bug, me being the programmer.

I have created开发者_如何学运维 a website with user profile. The user profile has many fields and an image. The image is uploaded just fine. First it is converted to fit into a certain area.

...

//I am uploading an image to the database.

imageConverter->loadImage($_FILE... blah balh).

...

When the user decides to change his information, he also has the chance to change his picture. The edit profile process IS THE EXACT SAME AS PROFILE STARTING process. The only difference is i check the fields he/she updated one at a time, and change that specific line int the database (obviously this can be done optimally, but first i want it to work :))

The confusing part is this. When i EDIT the profile information, the order goes like this. i use MYSQLI ($this->mysqli->query($query)).

these are edited in the database IF THEY ARE CHANGED

  • 1 firstname
  • 2 lastname
  • 3 password
  • 4 various preferences (check boxes / radio buttons).
  • 5 email
  • 6 profile picture.
  • 7 update session information with a query to the database for the most update information.

Now #7 returns a false (SELECT * FROM USERSINFO)

Now if i switch the order of action.

  • 1 firstname
  • 2 lastname
  • 3 password
  • 4 various preferences (check boxes / radio buttons).
  • 5 email
  • 6 update session information with a query to the database for the most update information.
  • 7 profile picture.

It works just FINE.

any answers? Does this mean that if 1000 people were trying to use my database at once that all there stuff would break?

Some code:

Inserting image (step #6 in not working example, #7 in working example)

$this->mysqli->query("DELETE FROM ".DB_REVIEW_IMAGE_TABLE." WHERE email='$email'");

if ($this->mysqli->query("INSERT INTO ".DB_REVIEW_IMAGE_TABLE." VALUES('$email', '$content', '$imageType')"))

Updating user information into session information. (step #7 in bad example, #6 in working example)

$this->userInfo = $_SESSION[SESSION_USER_INFO] = $database->getUserInfo($this->email);

which $database->getUserInfo($this->email) == "SELECT ".DB_USERS_ALL_MOUNTAIN.", ".DB_USERS_BACK_COUNTRY.", ".DB_USERS_GROOMERS.", ".DB_USERS_PARK.", ".DB_USERS_SEASON_DAYS.", ".DB_USERS_SEX.", ".DB_USERS_YEARS.", ".DB_USERS_FIRST_NAME.", ".DB_USERS_LAST_NAME.", ".DB_USERS_CITY.", ".DB_USERS_STATE." FROM ".DB_USER_INFO_TABLE.SQL_WHERE_EMAIL

I like to use constants :). And DB_USERS_SEX = male or female (just in case)

Michael


Ok the answer was simple.

My database class had a modular level var called $mysqli. This $mysqli was somehow getting used at the same time.

I my made 2 sequential calls.

  • updatePic
  • updateSessionInfo

Each used the database. But by having the modular level var $mysqli would somehow cause a conflict. Especially because session info and picture information are in two different databases. I must not know much about php, but these have to execute before the other one is finished. THEREFORE, to break this up, each method within the database

  • creates a connection to the database
  • sets the database to use.
  • executes the query
  • closes the connection / result sets.

Now it works!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号