fouzan Posted December 21, 2011 Share Posted December 21, 2011 I get this error-->Notice: Undefined index: name in C:\wamp\www\sedit.php on line 13 <?php session_start(); $db_handle = mysql_connect("localhost", "root", ""); $db_found = mysql_select_db("fouzan_db", $db_handle); if ($db_found) { echo "connected.<br/>"; if (isset($_POST['xyz'])) { $me = $_POST['text']; $sql="UPDATE `slogin` SET `data`='$me' WHERE username= '$_SESSION[name]'"; $result = mysql_query($sql); //to inform this is a query echo "Thank you for using our mail form"; } else { echo "<form method='post' action='sedit.php' /> Message:<br /> <textarea name='text' rows='15' cols='80'> </textarea><br /> <input type='submit'value='submit' name='xyz'/> </form>"; } } else { print "Database NOT Found "; mysql_close($db_handle); } ?> <html> <body> <head> </head> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253629-post-problem/ Share on other sites More sharing options...
Pikachu2000 Posted December 21, 2011 Share Posted December 21, 2011 Where have you assigned a value to, or even initialized $_SESSION['name']? Quote Link to comment https://forums.phpfreaks.com/topic/253629-post-problem/#findComment-1300228 Share on other sites More sharing options...
Maq Posted December 21, 2011 Share Posted December 21, 2011 var_dump($_SESSION) to see what the array looks like. And, in the future, please place OR tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/253629-post-problem/#findComment-1300229 Share on other sites More sharing options...
OneEyedWillie Posted December 21, 2011 Share Posted December 21, 2011 You didn't use the variable $result after you assigned it. Quote Link to comment https://forums.phpfreaks.com/topic/253629-post-problem/#findComment-1300230 Share on other sites More sharing options...
Samuz Posted December 21, 2011 Share Posted December 21, 2011 $sql="UPDATE `slogin` SET `data`='$me' WHERE username= '$_SESSION[name]'"; No single quotes. $_SESSION['name'] :V Quote Link to comment https://forums.phpfreaks.com/topic/253629-post-problem/#findComment-1300252 Share on other sites More sharing options...
Pikachu2000 Posted December 22, 2011 Share Posted December 22, 2011 It doesn't need single quotes within a double quoted string. In fact, quoting the array index within a double quoted string without using complex notation will throw this: Parsing Error: /Applications/MAMP/htdocs/test.php line 10 - syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING $query = "SELECT field FROM table WHERE field = '$_SESSION[name]'"; // This is fine $query = "SELECT field FROM table WHERE field = '{$_SESSION['name']}'"; // This is fine $query = "SELECT field FROM table WHERE field = '$_SESSION['name']'"; // Throws parse error. Quote Link to comment https://forums.phpfreaks.com/topic/253629-post-problem/#findComment-1300289 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.