Page 1 of 1

[solved] forgot session_start

Posted: Tue Jul 03, 2007 12:12 pm
by m2babaey
Hi
I want to insert the posted article into database plus the username of sender using this code:

Code: Select all

<?php
$title = $_POST['title'];
$subject = $_POST['subject'];
$article =$_POST['article'];
$username =$_SESSION['username'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());
mysql_query("INSERT INTO articles (subject, title, text ,username  ) VALUES('$subject','$title','$article','$username' )")
or die(mysql_error());  
mysql_close();
?>
But it says:
Notice: Undefined variable: _SESSION in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\another\htdocs\sendarticle.php on line 6
and the username is not sent. why is is not working?

Posted: Tue Jul 03, 2007 12:15 pm
by kaszu
If you are certain that $_SESSION['username'] exists, then only problem i see here is that session is not started, you need to call a session_start() to use it.
Also your script is vulnerable to SQL Injections.

Posted: Tue Jul 03, 2007 12:18 pm
by RobertGonzalez
Can you please edit your post title? 'Who is posting' has nothing to do with the real problem of you getting an undefined variable error.