Chris_Mc_1985 Posted August 20, 2009 Share Posted August 20, 2009 I am trying to post a username from a session to MYSQL. it works at the min but say the user name is mine chris. it is being posted as Arraychris. can any help? Here is the code I have for my page so far. <?php session_start(); $host="localhost"; $username=""; $password=""; $db_name=""; $tbl_name=""; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="INSERT INTO $tbl_name(name, comment)VALUES('$_POST$_SESSION[user]','$_POST[comment]')"; $result=mysql_query($sql); if($result){ echo "Successful, thank you for your feedback."; } else { echo "ERROR"; } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/171124-help-with-posting-a-username-from-session/ Share on other sites More sharing options...
Garethp Posted August 20, 2009 Share Posted August 20, 2009 Why $_POST$_SESSION[user]? Shouldn't it be $_SESSION[user] Also, have you tried echo $_SESSION['user']? Link to comment https://forums.phpfreaks.com/topic/171124-help-with-posting-a-username-from-session/#findComment-902413 Share on other sites More sharing options...
Chris_Mc_1985 Posted August 20, 2009 Author Share Posted August 20, 2009 I know it shouldnt be like that but carnt work out how it should be. echo does not work. have also tried $user=$_SESSION['user']; with POST[user] on the insert part Link to comment https://forums.phpfreaks.com/topic/171124-help-with-posting-a-username-from-session/#findComment-902423 Share on other sites More sharing options...
Garethp Posted August 20, 2009 Share Posted August 20, 2009 Try this <?php session_start(); $host="localhost"; $username=""; $password=""; $db_name=""; $tbl_name=""; $user = $_SESSION['user']; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="INSERT INTO $tbl_name(name, comment)VALUES('$user','$_POST[comment]')"; $result=mysql_query($sql); if($result){ echo "Successful, thank you for your feedback."; } else { echo "ERROR"; } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/171124-help-with-posting-a-username-from-session/#findComment-902426 Share on other sites More sharing options...
Chris_Mc_1985 Posted August 20, 2009 Author Share Posted August 20, 2009 thanks alot. works fine Link to comment https://forums.phpfreaks.com/topic/171124-help-with-posting-a-username-from-session/#findComment-902432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.