php mysql session help

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Fri Mar 01, 2013 2:57 am

php mysql session help

Postby taraphp » Fri Mar 01, 2013 3:29 am

or die('Error connecting to database');


$query="edit logindetail set 'firstname'=$firstname, set 'lastname'=$lastname', set 'gender'=$gender, set 'birthday'=$birthday,set 'city'=$city, set 'state'=$state WHERE id ='$_SESSION[Suserid]'";


echo'Successfully edited your profile<br/>';
echo'<a href="view.php">View my profile</a><br/>';
echo'<a href="edit.php">Edit profile</a><br/>';
echo'<a href="logout.php">Logout['.$_SESSION['Susername'] .']</a>';



session is keeping the track of id from the database so ,,is my query correct to edit data into the database am checking if the id in database is equal to the session ids since session id is tracking the value of id so am i allowed to do that or not ,,the code is running but not making the change in database..please help

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: php mysql session help

Postby seandisanti » Fri Mar 01, 2013 12:20 pm

You actually have a few issues going on here. the first is that you're using 'edit' instead of 'UPDATE'. sql isn't case sensitive, but it's common practice to make sql keywords all caps, and definitely using the right word helps immensely. :D You also only have to use the word 'SET' once in your update query. In addition to that, on your individual assignments in the sql string, you don't want to quote the field names, because that turns them into literal strings, but you DO want to put quotes around the string values and numeric values do not need to be quoted. so this line:
$query = "edit logindetail set 'firstname'=$firstname, set 'lastname'=$lastname', set 'gender'=$gender, set 'birthday'=$birthday,set 'city'=$city, set 'state'=$state WHERE id ='$_SESSION[Suserid]'";

would become....

Code: Select all

"UPDATE logindetail SET firstname='"$firstname "', lastname='"$lastname "', gender='" $gender "', birthday='" $birthday "',city='"$city "',state='" $state "' WHERE id=" $_SESSION['suserid'];

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 5 guests