need help with inserting data through form!!!
Posted: Thu May 07, 2009 6:34 pm
okay i have a form which has a message box, then i have a submit button. When you submit the form it goes to insert.php to know what to do with the info.
here's part of the form page code
for obviously reasons i didn't put my whole page code
here's the insert.php code
the thing is it looks like it would take the session username AND the message and insert it into the database. but all it puts in is the message, not the username. I need the username in there as well or my idea won't work.
if anyone can give me ANY help, please
Thanks in advance, Kedora19
here's part of the form page code
Code: Select all
<div id="content">
<form action="insert.php" method="post">
<textarea id="message" name="message" cols="30" rows="3"></textarea><br />
<input type="submit" name="add_message" value="Send" class="submit" />
</form>
</div>
here's the insert.php code
Code: Select all
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
?>
<?php
$con = mysql_connect("localhost","(myusername)","(mypassword)");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kiwirawk_cs", $con);
$sql="INSERT INTO Persons (username, message)
VALUES
('$_SESSION['user']','$_POST[message]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
if anyone can give me ANY help, please
Thanks in advance, Kedora19