I'm inserting a certain string value with a form in html(it's actually php, i'm echo-ing html) into mysql. Few days ago I inserted the value let's say "Ahhh". Now, i'm trying to insert something else, but it still brings up that old value. It's not the browsers cache nor is the value in my code wrong.
Form looks like this:
# form for adding a notice
echo "<form name='formAdd' action='controller.php' method='post'>";
echo "<input type='text' name='data' size='50'/>";
echo "<input type='hidden' name='user' value='$user' />";
echo "<input type='submit' name='submit' value='Add notice'/>";
echo "</form>";
I have 3 php files. functions.php, controller.php and the main file that shows content and creates the form that you can see above. The $user that i'm passing to controller.php is the right value that should be inserted (I print it and it's ok).
In controller.php I get the user by
if($_POST["user"]!=NULL){
# HERE he actually comes in, but gets another value from before.
$user = $_POST["user"];
}
After a call of a insert function I redirect back to the main file that should show me the updated value, but it shows the wrong one instead.
Any ideas?
additional info:
This gets the correct user in the main script.
# get username
$sql = "select username from user_auth where id=" . $_SESSION["sess_user_id"];
$result = mysql_query($sql) or die (mysql_error());
$name = mysql_fetch_array($result);
$user = $name['username'];
echo $user;
The functions.php looks like:
#cacti DB specifications
$database = "cacti";
$hostname = "localhost";
$username = "xxxxxx";
$password = "xxxxxx";
$port = "xxxx";
mysql_connect($hostname,$username,$password);
mysql_select_db($database);
function addNotice($data,$user,$date){
$sql = "INSERT INTO lalalal (data,user,date) VALUES ('$data','$user','$date')";
$result = mysql_query($sql) or die (mysql_error());
}
function deleteNotice($id){
$sql = "DELETE FROM lalalala WHERE id='$id'";
$result = mysql_query($sql) or die (mysql_error());
}
The controller.php looks like:
$user = NULL;
if($_POST["user"]!=NULL){
$user = $_POST["user"];
}
ini_set("display_errors", 1);
include_once("/var/www/html/cacti/plugins/lalala/functions.php");
$id = NULL;
$data = NULL;
$date = date('d.m.Y');
if($_POST["data"]!=NULL && $_POST["id"]==NULL){
$data = $_POST["data"];
addNotice($data,$user,$date);
}