officialakn Posted March 20, 2013 Share Posted March 20, 2013 How can i save data in $_SESSION['user'] ? Full script is this: <?php require_once('config.php'); if(!isset($_GET['actiune'])) $_GET['actiune'] = ''; if(!isset($_SESSION['logat'])) $_SESSION['logat'] = 'Nu'; if($_SESSION['logat'] != 'Da') { echo 'Pentru a accesa aceasta pagina, trebuie sa va autentificati. <br> Pentru a va autentifica, apasati <a href="autentificare.php">aici</a><br> Pentru a va inregistra, apasati <a href="inregistrare.php">aici</a>'; } else { switch($_GET['actiune']) { case '': echo '<h1>Profilul dumneavoastra</h1> Apasati <a href="profil.php?actiune=date_personale">aici</a> pentru a schimba datele personale.<br> Apasati <a href="profil.php?actiune=parola">aici</a> pentru a schimba parola dumneavoastra.<br><br> <a href="pagina.php">Intoarceti`va la pagina principala.</a>'; break; case 'date_personale': die("Utilizator:".$_SESSION['user']."<br />"); $cerereSQL = 'SELECT * FROM `utilizatori` WHERE utilizator="'.$_SESSION['user'].'"'; $rezultat = mysql_query($cerereSQL); while($rand = mysql_fetch_array($rezultat)) { echo '<table width="347" border="0" cellpadding="0" cellspacing="0"> <form name="formular" action="profil.php?actiune=validare" method="post"> <tr> <td height="50" colspan="4" valign="top"><h1>Modifica date personale</h1></td> </tr> <tr> <td width="80" height="19"> </td> <td width="15"> </td> <td width="214"> </td> <td width="38"> </td> </tr> <tr> <td height="10"></td> <td></td> <td></td> </tr> <tr> <td height="22" align="right" valign="top">Nume:</td> <td valign="top"></td> <td valign="top"><input type="text" name="nume" value="'.$rand['nume'].'"></td> <td></td> </tr> <tr> <td height="9"></td> <td valign="top"></td> <td></td> <td></td> </tr> <tr> <td height="22" align="right" valign="top">Prenume:</td> <td valign="top"></td> <td valign="top"><input type="text" name="prenume" value="'.$rand['prenume'].'"></td> <td></td> </tr> <tr> <td height="9"></td> <td valign="top"></td> <td></td> <td></td> </tr> <tr> <td height="22" align="right" valign="top">Varsta:</td> <td valign="top"></td> <td valign="top"><input type="text" size="3" maxLength="3" name="varsta" value="'.$rand['varsta'].'"> ani</td> <td></td> </tr> <tr> <td height="8"></td> <td valign="top"></td> <td></td> <td></td> </tr> <tr> <td height="22" align="right" valign="top">Localitate:</td> <td valign="top"></td> <td valign="top"><input type="text" name="localitate" value="'.$rand['localitate'].'"></td> <td></td> </tr> <tr> <td height="14"></td> <td valign="top"></td> <td></td> <td></td> </tr> <tr> <td height="24"></td> <td valign="top"></td> <td valign="top"><input name="Trimite" type="submit" id="Trimite" value="Modifica date"> <input name="Reseteaza" type="reset" id="Reseteaza" value="Reseteaza"> </td> <td></td> </tr> <tr> <td height="19"></td> <td valign="top"></td> <td> </td> <td></td> </tr> </form> </table>'; } break; case 'parola': echo '<table width="309" border="0" cellpadding="0" cellspacing="0"> <form name="formular" action="profil.php?actiune=validare" method="post"> <tr> <td height="36" colspan="4" valign="top"><h1>Modifica parola</h1></td> </tr> <tr> <td width="80" height="19" valign="top"> </td> <td width="15" rowspan="5" valign="top"></td> <td width="144" valign="top"> </td> <td width="70" valign="top"> </td> </tr> <tr> <td height="22" align="right" valign="top">Parola:</td> <td colspan="2" valign="top"> <input type="password" name="parola1" value=""> </td> </tr> <tr> <td height="7"></td> <td></td> <td></td> </tr> <tr> <td height="22" align="right" valign="top">Reintroduceti parola:</td> <td colspan="2" valign="middle"><input type="password" name="parola2" value=""></td> </tr> <tr> <td height="7"></td> <td></td> <td></td> </tr> <tr> <td height="24"> </td> <td valign="top"></td> <td colspan="2" valign="top"><input name="Trimite" type="submit" id="Trimite" value="Modifica parola"> <input name="Reseteaza" type="reset" id="Reseteaza" value="Reseteaza"> </td> </tr> <tr> <td height="24"> </td> <td valign="top"></td> <td> </td> <td> </td> </tr> </form> </table>'; break; case 'validare': if(!isset($_POST['parola1'])) $_SESSION['parola1'] = ''; else $_SESSION['parola1'] = $_POST['parola1']; if(!isset($_POST['parola2'])) $_SESSION['parola2'] = ''; else $_SESSION['parola2'] = $_POST['parola2']; if(!isset($_POST['nume'])) $_SESSION['nume'] = ''; else $_SESSION['nume'] = $_POST['nume']; if(!isset($_POST['prenume'])) $_SESSION['prenume'] = ''; else $_SESSION['prenume'] = $_POST['prenume']; if(!isset($_POST['varsta'])) $_SESSION['varsta'] = ''; else $_SESSION['varsta'] = $_POST['varsta']; if(!isset($_POST['localitate'])) $_SESSION['localitate'] = ''; else $_SESSION['localitate'] = $_POST['localitate']; if(($_POST['Trimite'] == 'Modifica date') && ($_SESSION['nume'] == '' || $_SESSION['prenume'] == '' || $_SESSION['varsta'] == '' || !is_numeric($_SESSION['varsta']) || strlen($_SESSION['varsta'] < 2) || $_SESSION['localitate'] == '')) { echo 'Completeaza campurile.<br> Apasa <a href="profil.php?actiune=date_personale">aici</a> pentru a te intoarce.'; } elseif(($_POST['Trimite'] == 'Modifica date') && ($_SESSION['nume'] != '' || $_SESSION['prenume'] != '' || $_SESSION['varsta'] != '' || is_numeric($_SESSION['varsta']) || strlen($_SESSION['varsta'] >= 2) || $_SESSION['localitate'] != '')) { echo 'Datele au fost modificate. <br> Apasa <a href="pagina.php">aici</a> pentru a te intoarce la pagina principala.'; $cerereSQL = "UPDATE `utilizatori` SET nume='".addentities($_SESSION['nume'])."', prenume='".addentities($_SESSION['prenume'])."', varsta='".addentities($_SESSION['varsta'])."', localitate='".addentities($_SESSION['localitate'])."' WHERE utilizator='".$_SESSION['user']."'"; mysql_query($cerereSQL); $_SESSION['nume'] = ''; $_SESSION['prenume'] = ''; $_SESSION['varsta'] = ''; $_SESSION['localitate'] = ''; } elseif(($_POST['Trimite'] == 'Modifica parola') && ($_SESSION['parola1'] == '' || $_SESSION['parola1'] != $_SESSION['parola2'])) { echo 'Completeaza campurile.<br> Apasa <a href="profil.php?actiune=parola">aici</a> pentru a te intoarce.'; } elseif(($_POST['Trimite'] == 'Modifica parola') && ($_SESSION['parola1'] != '' || $_SESSION['parola1'] == $_SESSION['parola2'])) { echo 'Parola a fost modificata. <br> Apasa <a href="pagina.php">aici</a> pentru a te intoarce la pagina principala.'; $cerereSQL = "UPDATE `utilizatori` SET parola='".md5($_SESSION['parola1'])."' WHERE utilizator='".$_SESSION['user']."'"; mysql_query($cerereSQL); $_SESSION['parola1'] = ''; $_SESSION['parola2'] = ''; } break; } } ?> I asked elsewhere and they told me that I can not save data in $_SESSION['user']. My raw from table with user is called utilizatori. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/ Share on other sites More sharing options...
Barand Posted March 20, 2013 Share Posted March 20, 2013 if a page uses $_SESSION you have to call session_start() at the top of the script. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1419935 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 Where exactly I have to put in? Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420069 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 if a page uses $_SESSION you have to call session_start() at the top of the script. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420072 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 I have that session_start() in config.php. I have read that is enough if is there. Somebody else says that is not created $_SESSION['user']. I think the code is this: $_SESSION['user'] = $rand['utilizator']; But i don't know where to put it.. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420078 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 Wherever you want. Just make sure it's after session_start(), and that $rand['utilizator'] is set before this point. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420079 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 So i have to set $rand before $_SESSION['user'] = $rand['utilizator']; ? How to set $rand? Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420081 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 $rand['utilizator'] = 'something'; Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420082 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 (edited) Where ever i put them, is not working...Would you insert code in my script and i will insert in my page to see if it's working? Edited March 21, 2013 by officialakn Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420084 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 My putting it in your script isn't going to do anything. I don't know what your script is supposed to do, and I don't know what you are trying to do. Why don't you tell us what you mean by 'it's not working'. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420087 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 This script is used to modify data in the table, the user connected. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420090 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 (edited) Somebody else told me that I didn't saved data in $_SESSION['user']. Now i know the codes (above) but I don't know where to insert them. Edited March 21, 2013 by officialakn Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420091 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 Sorry, but you haven't given us enough information to be able to help you any more than we already have. You are on your own. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420095 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 First, the script check if you're logged in or not. Then you pull in the account database, which is passed in the form: $ _SESSION ['user']. That does not reads and from here starts erroarea. Below the script are displayed logged user options (change name, surname, password, age, location). Is that enough? Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420098 Share on other sites More sharing options...
PaulRyan Posted March 21, 2013 Share Posted March 21, 2013 You must put the following after the PHP opening tags, and before anything else. session_start(); *Unless the session start is in the 'config.php' file. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420108 Share on other sites More sharing options...
haku Posted March 21, 2013 Share Posted March 21, 2013 I have that session_start() in config.php. I have read that is enough if is there. Somebody else says that is not created $_SESSION['user']. I think the code is this: Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420110 Share on other sites More sharing options...
PaulRyan Posted March 21, 2013 Share Posted March 21, 2013 I have that session_start() in config.php. I have read that is enough if is there. Somebody else says that is not created $_SESSION['user']. I think the code is this: Totally missed that, must have scrolled right past it. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420114 Share on other sites More sharing options...
officialakn Posted March 21, 2013 Author Share Posted March 21, 2013 I don't get it.. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420128 Share on other sites More sharing options...
officialakn Posted March 22, 2013 Author Share Posted March 22, 2013 Totally missed that, must have scrolled right past it. What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420268 Share on other sites More sharing options...
PaulRyan Posted March 22, 2013 Share Posted March 22, 2013 Officialakn, that message was to Haku, as he pointed out something I over looked. Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420277 Share on other sites More sharing options...
officialakn Posted March 23, 2013 Author Share Posted March 23, 2013 Aaaa. Guys, i made it yesterday and it worked. And now, with no modifications since yesterday, is not working:( Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420502 Share on other sites More sharing options...
officialakn Posted March 23, 2013 Author Share Posted March 23, 2013 I realy don't understand... Quote Link to comment https://forums.phpfreaks.com/topic/275937-i-have-a-small-problem/#findComment-1420503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.