Jump to content

Trouble with session string for mysql


paulc8481

Recommended Posts

Can someone please explain to me why I cant seem to get my mysql update line to work.  I have been trying for a while an still nothing.  I am new in php and need some help getting this to work.  Please be gentle.  a good explaination in newbie talk would be appreciated.

 

The session variable I echoed out does work so I know I am reading the variable in from the other page.

 

thanks

 

<?php

session_start();

 

/*

Server side scripting with php

CISS 225

Lab # Final Project

*/

//This section will create variables collected from information sent

//by the post method on the createUserProcess.

 

/*      $_SESSION['city'] = $_POST['city'];

$_SESSION['state'] = $_POST['state'];

$_SESSION['zipCode'] = $_POST['zipCode'];

$_SESSION['profession'] = $_POST['profession'];

$_SESSION['activities'] = $_POST['activities'];

$_SESSION['hobbies'] = $_POST['hobbies'];

*/

$city = $_POST['city'];

$state = $_POST['state'];

$zipCode = $_POST['zipCode'];

$profession = $_POST['profession'];

$activities = $_POST['activities'];

$hobbies = $_POST['hobbies'];

 

$db = mysql_connect("localhost", "root", "");

mysql_select_db("accountprofile",$db);

 

echo $_SESSION['Email'];

//$query = "UPDATE accountprofile SET city = '$city', state = '$state', zipcode = '$zipCode', profession = '$profession', " . "

//activities = '$activities', hobbies = '$hobbies' WHERE lastName = 'Hildebrand'";

$query = "UPDATE accountprofile SET city = '$city', state = '$state', zipcode = '$zipCode', profession = '$profession',

activities = '$activities', hobbies = '$hobbies' WHERE userName = " .$_SESSION['Email']."";                 mysql_query($query,$db);

if (mysql_error())

{

    echo "$query<br />";

    echo mysql_error();

}

 

echo "THANK YOU!<br />";

echo "Your profile has been completed!<br />";

?>

Link to comment
https://forums.phpfreaks.com/topic/253722-trouble-with-session-string-for-mysql/
Share on other sites

$query = "UPDATE accountprofile SET city = '$city', state = '$state', zipcode = '$zipCode', profession = '$profession',
   activities = '$activities', hobbies = '$hobbies' WHERE userName = '" .$_SESSION['Email']."'";

 

or more simply (less error prone, less typing) -

 

$query = "UPDATE accountprofile SET city = '$city', state = '$state', zipcode = '$zipCode', profession = '$profession',
   activities = '$activities', hobbies = '$hobbies' WHERE userName = '{$_SESSION['Email']}'";

 

Are you sure your userName column contains email addresses?

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.