Hey I am new to PHp and I am trying to enter details into my database. I am trying to enter an eventname- which the user enters (POST) and the username of the logged in user.
I have created sessions to store users usernames, the code i have is
$eventname=$_POST['eventname'];
$myusername = $_SESSION['myusername']
$sql = mysql_query("INSERT INTO $tbl_nameVALUES('','$eventname','$_SESSION['myusername'])");
echo "You have been added to the event";
Its the $sql statement which is giving the error? any help would be much appreciated.
Thanks all!
There are several potential problems here.
First, you have not escaped
eventnameagainst SQL injection. We assume hopefully thatmyusernameis already safe. If it has not been previously filtered, also usemysql_real_escape_string()on$_SESSION['myusername'].Finally, in order for the statement to work, it assumes you have exactly three columns in
$tbl_name. You should be explicit about the columns used. Substitute the correct column names forcolname1, event_name, username.The exact locations of SQL syntax errors will be revealed to you with some basic error checking via
mysql_error().