Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

php mysql session help

Codes here !

Moderators: macek, egami, gesf

php mysql session help

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

<?php
session_start();
if(isset($_SESSION['Suserid']))
{
if(isset($_POST['submit']))
{
$dbconnect=mysqli_connect('localhost','root','','mismatch')
or die('Error connecting to database');

$firstname=mysqli_real_escape_string($dbconnect,trim($_POST['firstname']));
$lastname=mysqli_real_escape_string($dbconnect,trim($_POST['lastname']));
$gender=mysqli_real_escape_string($dbconnect,trim($_POST['gender']));
$birthday=mysqli_real_escape_string($dbconnect,trim($_POST['birthday']));
$city=mysqli_real_escape_string($dbconnect,trim($_POST['city']));
$state=mysqli_real_escape_string($dbconnect,trim($_POST['state']));

$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]'";

mysqli_query($dbconnect,$query);

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>';


mysqli_close($dbconnect);


}

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
taraphp
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Mar 01, 2013 2:57 am

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

$query 
"UPDATE logindetail SET firstname='"$firstname "', lastname='"$lastname "', gender='" $gender "', birthday='" $birthday "',city='"$city "',state='" $state "' WHERE id=" $_SESSION['suserid'];
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.