开发者

submit a form whose value is changing

I have a form in that i am getting the initial value of form from mysql and then javascript changes the value (e开发者_运维百科very second that value increases by 1 ) but when i submit the form it submits the initial value what i have got from mysql .

please tell how to submit the updated value for example if i have retrieved 40 as form value from MySQL then it keeps on increasing but as in form value is coming from MySQL when i submit it submits 40 only but in actual my form value increases every second please tell how to submit updated value in MySQL. here is my code.


I realized your problem: You are fetching the value before the UPDATE, so you are always getting the old value. Make sure you run the SELECT after the UPDATE so you can get the new value. Try something like this:

// Only update if a value was posted
if (isset($_POST['Time_Spent1']))
{
    // Cast to integer or use mysql_real_escape_string() here to protect the query
    $new_value = (integer) $_POST['Time_Spent1'];
    sql_query( "update jcow_accounts set Time_Spent = '{$new_value}' where id = '{$client['id']}' " );
}

// Run SELECT afterwards, in case the value was updated
$res = sql_query("select * from jcow_accounts where id='{$client['id']}'");

$row = sql_fetch_array($res);

$Time = $row['Time_Spent'];

echo '<form name="form1" method="post" action="">
<p>Earning: <input name="Time_Spent1"  value="'.$Time.'" id="Time_Spent1"   type="text" size="7"  /></p>
<input type="submit" name="Submit" value="submit" />
</form>'

So, it was nothing to do with the $_POST value, the value that you used to repopulate the form input from the database was "old". There's plenty of other things I could nitpick about the code, and I'm tempted to, but this should get you moving forward.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜