Jump to content

Help with posting a username from session


Chris_Mc_1985

Recommended Posts

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();

?>

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();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.