Jump to content

Recommended Posts

I made a webpage using php that allows user to update mysql database through an html form. There is an option on this page that disables modification, so it only displays the current data. However after the user submits the data and goes back to this page, the data has not been updated (while the db is).

 

Has this got something to do with sessions or cookies? Thanks a lot!

Link to comment
https://forums.phpfreaks.com/topic/149264-mysql-update-issue/
Share on other sites

Basically, when user updates the data from the webpage, although the database has been updated, the result is not shown on the webpage. All the data shown on the webpage are the old ones before the update. This is weird because the data on the webpage comes from the database, but now they have a mismatch.

 

It takes some time and/or a reboot for web explorer for the new data to be shown on the webpage

Link to comment
https://forums.phpfreaks.com/topic/149264-mysql-update-issue/#findComment-783912
Share on other sites

 

echo "<form name=\"input\" action=\"mysql_test_comments_added.php\" method=\"post\">";

echo "<table border=\"1\">";

 

echo "<tr><td>User</td><td>Comments</td><td>Comment Date</td></tr>";

 

while ($sapedUsers[$i]) {

$result = mysql_query("SELECT * FROM ".$comments_tb." WHERE Project_Key=$PKey AND user=\"$sapedUsers[$i]\"") or die(mysql_error()); 

 

$row = mysql_fetch_array( $result );

 

 

if ($editable != 1) {

$ltstring = " readonly=\"readonly\" ";

$ltstring2 = " style=\"border:none;\" ";

} else {

$ltstring = " ";

$ltstring2 = " ";

}

echo "<tr><td>"."<input".$ltstring2."type=\"text\"".$ltstring."name=\"user[".$i."]\" value=\"".$sapedUsers[$i]."\">";

echo "</td><td>"."<input".$ltstring2."type=\"text\"".$ltstring."name=\"comment_link[".$i."]\" value=\"".$row['comment_Link']."\">";

echo "</td><td>"."<input".$ltstring2."type=\"text\"".$ltstring."name=\"comments_Date[".$i."]\" value=\"".$row['comment_date']."\">";

echo "</td></tr>";

 

 

$i = $i + 1;

}

 

echo "<input type=\"hidden\" name=\"item_index\" value=\"".$i."\">";

echo "<input type=\"hidden\" name=\"Project_Key\" value=\"".$PKey."\">";

echo "</table>";

 

if ($editable == 1) {

echo "<br><input type=\"submit\" value=\"Submit\">";

}

echo "</form>";

 

_______________________________________________________________

 

 

and here's the target of the form:

 

 

$user = $_POST["user"];

$comment_link = $_POST["comment_link"];

$Project_Key = $_POST["Project_Key"];

$comments_Date = $_POST["comments_Date"];

$item_index = $_POST["item_index"];

 

$i = 0;

 

while ($i < $item_index) {

$result = mysql_query("SELECT * FROM ".$comments_tb." WHERE Project_Key=$Project_Key AND user=\"$user[$i]\"") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

 

if (!$row) {

$goodreq = "INSERT INTO ".$comments_tb." (`user`, `comment_Link`, `project_Key`, `comment_Date`)

VALUES ('$user[$i]', '$comment_link[$i]', '$Project_Key', '$comments_Date[$i]');";

} else {

$goodreq = "UPDATE ".$comments_tb." SET `comment_Link` = '$comment_link[$i]', `comment_date` = '$comments_Date[$i]'

WHERE Project_Key=$Project_Key AND user='$user[$i]'";

}

echo $goodreq;

mysql_query($goodreq) or die(mysql_error());

$i = $i + 1;

}

Link to comment
https://forums.phpfreaks.com/topic/149264-mysql-update-issue/#findComment-783967
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.