php - How to add a value from a HTML form to a value in a database -


i trying create form allow user update data form existing amount in database. here have far appears double value. thinking needed pull value database , add data form.

<?php  $username = "username"; $password = "password"; $hostname = "localhost";  //connection database $dbhandle = mysql_connect($hostname, $username, $password)  or die("unable connect mysql"); echo "<font face=tahoma color=#ff000><b>connected mysql</b></font><br><br>";  //select database work $selected = mysql_select_db("pdogclan_points",$dbhandle)   or die("did change");  // formulate query $_post["filter"]; $memid = mysql_real_escape_string($_post["member_id"]); $query = sprintf("select member_id, bank, reward_1, reward_2, reward_3 points_rewards member_id = '$memid'") or die("could not formulate query");  //execute sql query , return records $result = mysql_query($query);  // check result // shows actual query sent mysql, , error. useful debugging. if (!$result) {     $message  = 'invalid query: ' . mysql_error() . "\n";    $message .= 'whole query: ' . $query;     die($message); }  //fetch tha data database while ($row = mysql_fetch_array($result))    echo "<table width=750 cellspacing=2 cellpadding=2 border=2>         <tr>             <td bgcolor=#000000 width=150><font face=tahoma color=white>id: {$row['member_id']}</font></td>".              "<td width=150><font face=tahoma>bank: {$row['bank']}</td>".              "<td width=150><font face=tahoma>reward 1: {$row['reward_1']}</td>".              "<td width=150><font face=tahoma>reward 2: {$row['reward_2']}</td> ".              "<td width=150><font face=tahoma>reward 3: {$row['reward_3']}</td>         </tr>   </table><br></font>";//display results // formulate update query $_post["submit"]; $memid = mysql_real_escape_string($_post["member_id"]); $query = sprintf("select member_id, bank, reward_1, reward_2, reward_3 points_rewards member_id = '$memid'") or die("could not formulate query");  while ($row = mysql_fetch_array($result)) { $bankdb = $row['bank']; $reward1db = $row['reward_1']; $reward2db = $row['reward_2']; $reward3db = $row['reward_3']; } echo $bank; echo $reward1; echo $reward2; echo $reward3; $memid = mysql_real_escape_string($_post["member_id"]); $bank = $_post['bank']; $reward1 = $_post['reward1']; $reward2 = $_post['reward2']; $reward3 = $_post['reward3'];    $query = "update points_rewards set bank = ('$bank' + '$bankdb'), reward_1 =    ('$reward1' + '$reward1'), reward_2 = ('$reward2' + '$reward2'), reward_3 = ('$reward3' + '$reward3') member_id = '$memid'"; $result = mysql_query($query) or die(mysql_error());    if(mysql_query($query)){ echo "updated";} else{ echo "fail";}  //close connection mysql_close($dbhandle); ?> 

just create form using basic html, store data fetched database in php variables, display data using php tags, this:

<form action="..." method="post" > <?php $memid = mysql_real_escape_string($_post["member_id"]); $query = sprintf("select member_id, bank, reward_1, reward_2, reward_3 points_rewards member_id = '$memid'") or die("could not formulate query");  while ($row = mysql_fetch_array($result)) { ?> <input type="text" name="r1" value="<?php echo $row['reward_1']; ?>" /> ; <input type="text" name="r2" value="<?php echo $row['reward_2']; ?>" /> ; <input type="text" name="r3" value="<?php echo $row['reward_3']; ?>" /> ; ...     <?php  } ?>     ... </form> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -