Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:23:37+00:00 2026-06-07T17:23:37+00:00

I’m inserting a certain string value with a form in html(it’s actually php, i’m

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:23:38+00:00Added an answer on June 7, 2026 at 5:23 pm

    solved:

    # 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;
    
    # get data
    $sql = "SELECT * FROM lalala";
    $result = mysql_query($sql) or die (mysql_error());
    
    echo "<table CELLPADDING=2 border=1 align=center>";
    echo "<tr>";
    echo "<th>User</th>";
    echo "<th>Notice</th>";
    echo "<th>Date</th>";
    echo "</tr>";
    
    while($row = mysql_fetch_array($result)){
        $id = $row['id'];
        $user = $row['user'];
        $data = $row['data'];
        $date = $row['date'];
    
        echo "<tr>";
        echo "<td>".$user."</td>";
        echo "<td>".$data."</td>";
        echo "<td>".$date."</td>";
        echo "<td><form name='formDelete' action='controller.php' method='post'>";
        echo "<input type='hidden' name='id' value='$id' />";
        echo "<input type='submit' name='submit' value='Delete'/>";
        echo "</form></td>";
        echo "</tr>";
    }
    
    echo "</table><br>";
    
    # 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>";
    

    The problem was that there were 2 $user variables. And the one that got into a form was the last one displayed in a html table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
i got an object with contents of html markup in it, for example: string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.