iamjp Posted October 2, 2014 Share Posted October 2, 2014 (edited) I am 3rd yr college student and enrolled to a subject web programming and right now i am developing a web based tabulation for scoring contestants. i am having a trouble regarding on how to update a record(score) in database when the judge is giving a score to the contestant using a textbox and a button .. the problem is that it didnt read the value from an inputed textbox btw the textbox and the button was inside a do while loop so everytime a new contestant was added the image will be retrieved and another textbox and button will be placed..(to sum up, every contestant has a button and textbox for inputing the score) HERE IS THE CODE.. --------> Do while for retrieving image and textboxes do{ $count++; echo "<td style='color:#C90;font-weight:bold;font-size:12px;' >"; echo "<div id = 'hover'>"; echo "<img src = 'images/" . $result['imagename'] . "' height='300px;' width='300px;' class='img'>"; echo '<br/>'; echo $result['Name']; echo '<br/>'; echo $result['course']; echo '<br/>'; echo $result['branch']; $ID = $result['ID']; echo $result['ID']; echo '<div class = "hover">'; echo "<form method='post' style='position:relative; bottom:-120px; right:-50px;'>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "SCORE"; echo "</td>"; echo "<td>"; echo '<input type="text" name="txtscore" style="height:30px; width:50px; background-color:#923227; box-shadow:1px 1px #FFF; color:#C90;font-weight:bold; font-size:16px;"/>'; echo "</td>"; echo "<td>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</form>"; echo "<a href = 'fasttrackscw.php?id=".$ID."'>"; echo "<input type='submit' name='btn1'>"; echo "</a>"; echo '</div>'; echo "</div>"; echo "</td>"; $result=mysql_fetch_assoc($query); if($count >= $max){ //reset counter $count = 0; //end and restart echo "</tr><tr>"; } } while($result); --------> Query for updating if(isset($_POST['btn'])){ @$id =$_GET['id']; $sql = "update tblfastracks set casualwear = '$_POST[txtscore]' where contestantid = '$id'"; mysql_query($sql,$connection); } Edited October 2, 2014 by mac_gyver code tags please Quote Link to comment Share on other sites More sharing options...
Barand Posted October 2, 2014 Share Posted October 2, 2014 Change these lines echo "</form>"; echo "<a href = 'fasttrackscw.php?id=".$ID."'>"; echo "<input type='submit' name='btn1'>"; echo "</a>"; to echo "<input type='hidden' name='id' value='$ID'>"; echo "<input type='submit' name='btn'>"; echo "</form>"; so the id and txtscore are both POSTed in the form data when the submit button ("btn" by the way) is clicked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.